MySQL base image using Ubuntu 16.04 Xenial
2.7K
Uses Ubuntu Xenial as base image.
sudo docker build --rm -t lysender/mysql .
We need a volume container to hold our MySQL data.
sudo docker create --name mysql-data \
-v /var/lib/mysql \
-v /var/log/mysql \
lysender/mysql /bin/true
sudo docker run --rm \
--volumes-from=mysql-data \
-e "ROOT_PASSWORD=the_root_password" \
lysender/mysql /config_root_account.sh
Note: Only use this if you need root-like privilege on all databases (ex: on dev environment)
sudo docker run --rm \
--volumes-from=mysql-data \
-e "ROOT_PASSWORD=the_root_password" \
-e "DB_USER=genericdb" \
-e "DB_PASS=genericdb" \
lysender/mysql /config_power_credentials.sh
sudo docker run --rm \
--volumes-from=mysql-data \
-e "ROOT_PASSWORD=the_root_password" \
-e "DB_NAME=blog" \
-e "DB_USER=bloguser" \
-e "DB_PASS=blogpassword" \
lysender/mysql /config_credentials.sh
Note: The example below forwards localhost's port 3307 to the mysql container. You may use a different port or use the default port 3306.
sudo docker run --name mysql \
--volumes-from=mysql-data \
-d \
-p 3307:3306 \
lysender/mysql
mysql --protocol tcp --port 3307 --user blog -p -D blog
mysql --protocol tcp --port 3307 --user blog -p -D blog < /path/to/blog-backup.sql
Note: This is just an example and may not work without prior preparation like creating volume containers or a web app image.
sudo docker run --name "blog-webapp" \
-d \
-p 8080:80 \
--volumes-from "blog-data" \
--link mysql:db \
my-blog-webapp-image
The blog-webapp container will have access to the MySQL server via db hostname (note the db alias). Set the DB hostname in the blog webapp to db.
Content type
Image
Digest
Size
155.3 MB
Last updated
over 8 years ago
docker pull lysender/mysql