Накидал несколько скриптов для удобства.
MySQL
#!/bin/bash
CONTAINER_NAME='mysql-dev'
ROOT_PASSWORD='123456'
ACTION='start'
if [ -n "$1" ]
then
ACTION=$1
fi
echo 'Action: ' $ACTION;
if [ $ACTION = 'start' ]
then
if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]
then
echo 'Already run'
fi
if [ "$(docker ps -q -f name=$CONTAINER_NAME -a)" ]
then
echo 'Start'
docker start $CONTAINER_NAME
else
echo 'Run'
docker \
run \
--detach \
--env MYSQL_ROOT_PASSWORD=$ROOT_PASSWORD \
--env MYSQL_ROOT_HOST=% \
--name $CONTAINER_NAME \
--publish 3306:3306 \
mysql;
fi
fi
if [ $ACTION = 'stop' ]
then
docker stop $CONTAINER_NAME
fi
docker ps
Redis
#!/bin/bash
CONTAINER_NAME='redis-dev'
ROOT_PASSWORD='123456'
ACTION='start'
if [ -n "$1" ]
then
ACTION=$1
fi
echo 'Action: ' $ACTION;
if [ $ACTION = 'start' ]
then
if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]
then
echo 'Already run'
fi
if [ "$(docker ps -q -f name=$CONTAINER_NAME -a)" ]
then
echo 'Start'
docker start $CONTAINER_NAME
else
echo 'Run'
docker \
run \
--detach \
--name $CONTAINER_NAME \
--publish 6379:6379 \
redis;
fi
fi
if [ $ACTION = 'stop' ]
then
docker stop $CONTAINER_NAME
fi
docker ps
RabbitMQ
#!/bin/bash
CONTAINER_NAME='rabbit-dev'
ROOT_PASSWORD='123456'
ACTION='start'
if [ -n "$1" ]
then
ACTION=$1
fi
echo 'Action: ' $ACTION;
if [ $ACTION = 'start' ]
then
if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]
then
echo 'Already run'
fi
if [ "$(docker ps -q -f name=$CONTAINER_NAME -a)" ]
then
echo 'Start'
docker start $CONTAINER_NAME
else
echo 'Run'
docker \
run \
--detach \
--hostname my-rabbit-dev \
--name $CONTAINER_NAME \
--publish 5672:5672 \
rabbitmq;
fi
fi
if [ $ACTION = 'stop' ]
then
docker stop $CONTAINER_NAME
fi
docker ps
Для остановки всех контейнеров
#!/bin/bash
docker stop $(docker ps -aq)
docker ps