Docker is an application that simplifies the create/deploy/run software dev cycle by using the concept of containers. A container is a way to package up an application and all of its dependencies.
Do the following to get Docker installed and a MySQL server running in a container.
- Install Docker (Community Edition) from:
- On Mac, use terminal for the following. On Windows, use a Cmd prompt:
- Verify Docker is working:
docker --version
- Use this command to start a Docker container running mysql:
docker run -p 3306:3306 -d --name mysql01 -e MYSQL_ROOT_PASSWORD=password mysql/mysql-server
- replace password with a password you would like to give the root user of mysql. Do not use an important password that you’ve used elsewhere.
- The first time you run this, it will have to download some files from the Internet.
-p 3306:3306
maps a port of the container to the host machine--name mysql01
names the container mysql (may be used when executing other commands related to this container)-e MYSQL_ROOT_PASSWORD=password
sets an environment variable to be used inside the container. In this case, it is a way to provide the initial root password to MySQL as the container is created.- mysql/mysql-server is the
- Start a Bash shell in the Docker container you just created:
This executes a Bash shell inside mysql01 container. You will know it worked if you are presented with a prompt that says
docker exec -it mysql01 bash
bash-4.2#
. - At the Bash prompt, log in to to MySQL server using the mysql command line client
mysql -u root -p
You’ll then be prompted for a password. Type the password you used in Step 2 above. Note, the cursor WILL NOT MOVE as you type.- If you’re presented with the mysql prompt
mysql>
, then everything should be working.
- If you’re presented with the mysql prompt
- In mysql, type
exit
to quit. - At the Bash prompt, type
exit
to return to your Host OS’ shell.
- Verify Docker is working:
Some other useful Docker Commands:
docker stop mysql01
- stop the container named mysql01
docker start mysql01
- restart the container named mysql01
docker cp foo.txt mycontainer:/tmp/foo.txt
- copy file foo.txt into container named <mycontainer> at path /tmp
More info on Docker:
Speak Your Mind