Skip to content

Instantly share code, notes, and snippets.

@seveniu
Last active September 25, 2015 06:42
Show Gist options
  • Save seveniu/e6c86666dbf0fa56a05c to your computer and use it in GitHub Desktop.
Save seveniu/e6c86666dbf0fa56a05c to your computer and use it in GitHub Desktop.
用于创建一个MySQL docker 容器,用的 docker file 是官方的 https://github.com/docker-library/mysql
#!/bin/bash
######## eg.
#./run.sh mysql-test password /home/java/conf-files/mysql 3306 official/mysql:5.7 /data/mysql/test/
########
name=$1
password=$2
confDir=$3
port=$4
image=$5
dataDir=$6
if [ -n "$name" ]; then
echo "name : ${name}";
else
echo "name not set";
exit;
fi
if [ -n "$password" ]; then
echo "password : ${password}";
else
echo "password not set";
exit;
fi
if [ -n "$confDir" ]; then
echo "confDir: ${confDir}";
else
echo "confDir not set";
exit;
fi
if [ -n "$port" ]; then
echo "port: ${port}";
else
echo "port not set";
exit;
fi
if [ -n "$image" ]; then
echo "image: ${image}";
else
echo "image not set";
exit;
fi
if [ -n "$dataDir" ]; then
echo "dataDir: ${dataDir}";
else
echo "dataDir not set";
exit;
fi
mkdir -p $dataDir
command="docker run --name ${name} -v ${confDir}:/etc/mysql/conf.d -v ${dataDir}:/var/lib/mysql -p ${port}:3306 -e MYSQL_ROOT_PASSWORD=${password} -d ${image}"
echo "${command}"
eval ${command}
#### 修改 docker 时间
docker exec -it ${name} bash -c "echo Asia/Shanghai > /etc/timezone"
docker exec -it ${name} bash -c "dpkg-reconfigure -f noninteractive tzdata"
docker restart ${name}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment