-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmysqldocker
More file actions
42 lines (31 loc) · 1.19 KB
/
mysqldocker
File metadata and controls
42 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# Check if the "mysql" container is running
number_of_running_containers=$(docker ps --filter "name=mysql" | grep -w "mysql" | wc -l)
if [ $number_of_running_containers = "1" ] ; then
echo "MySQL is already running:"
docker ps --filter "name=mysql"
echo "You can stop it by executing \"docker stop mysql\""
exit 0
fi
# Doing the same kind of check but with "-a", to check if the container exists.
number_of_running_containers=$(docker ps -a --filter "name=mysql" | grep -w "mysql" | wc -l)
if [ $number_of_running_containers = "1" ] ; then
echo "Container exists."
else
echo "Container does not exist yet, creating it..."
docker create \
--name=mysql \
--env MYSQL_ROOT_PASSWORD=root \
--publish 3306:3306 \
--volume=/var/tmp/mysql_docker_data:/var/lib/mysql \
mysql:5.7
fi
echo "Starting MySQL..."
docker start mysql
sleep 0.5
number_of_running_containers=$(docker ps --filter "name=mysql" | wc -l)
if [ $number_of_running_containers = "1" ] ; then
echo "/!\ Seems like the container did not start."
echo "Last logs:"
docker logs mysql --since=2s
fi