<code>
#!/bin/bash
netexist=$(docker network ls --format "{{.Name}}" -f "name=rccc")
if [[ $1 == "start" ]]; then
if [[ -z $netexist ]]; then
docker network create rccc
fi
docker run -d --name mysql --network rccc \
-v $(pwd)/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=mysecret \
-e MYSQL_DATABASE=wordpress \
-e MYSQL_USER=tongli -e MYSQL_PASSWORD=secret \
mysql:latest mysqld --default-authentication-plugin=mysql_native_password
sleep 3
while : ; do
res=$(docker logs mysql 2>&1 | grep 'ready for connections')
if [[ ! -z $res ]]; then
break
fi
echo 'Waiting for mysql to be ready...'
sleep 3
done
docker run -d --name rcccsite --network rccc \
-v $(pwd)/content:/var/www/html \
-e WORDPRESS_DB_HOST=mysql \
-e WORDPRESS_DB_USER=tongli \
-e WORDPRESS_DB_PASSWORD=secret \
-e WORDPRESS_DB_NAME=wordpress \
-p 8080:80 wordpress:latest
elif [[ $1 == "stop" ]]; then
docker rm -f rcccsite mysql
if [[ $netexist == "rccc" ]]; then
docker network rm rccc
fi
fi
</code>
No comments:
Post a Comment