Daily Archives: April 7, 2018

18. DevOps: How to create a MySQL docker container ?

Docker-logo

MySql DB docker container:

In this blog I would like to demonstrate the container creation for MYSQL DB.

The following dockerfile code can be used to create the mysqldb container:
I have made this as  group of commands to be executed from Ubuntu CLI.
=== Dockerfile code for MySql DB=====>
sudo docker container run \
–detach \
–name mysqldb \
-e MYSQL_ROOT_PASSWORD=my-secret-pw \
mysql:latest
=== To create mysqldb container ====>

=== Screen output ====>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo docker container run \
> –detach \
> –name mysqldb \
> -e MYSQL_ROOT_PASSWORD=my-secret-pw \
> mysql:latest
dcfc16b7fba9075c59035e29a0efed91b7872e5f5cf72c8656afade824651041
vskumar@ubuntu:~$
==== Created mysql =====>

Please note this time, I have not copied the complete display contents.

=== listed ====>
vskumar@ubuntu:~$ sudo docker image ls mysql
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 5d4d51c57ea8 5 weeks ago 374MB
vskumar@ubuntu:~$

vskumar@ubuntu:~$ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dcfc16b7fba9 mysql:latest “docker-entrypoint.s…” 3 minutes ago Up 3 minutes 3306/tcp mysqldb
a5f1ce30c02d swarm “/swarm manage” 11 days ago Restarting (1) 28 seconds ago gracious_bhabha
vskumar@ubuntu:~$
=================>

So we can have the mysql container also running in background currently.

Let us understand the commands/options used for dockerfile syntax:

Using ‘–detach’ command it runs the container in background.
I have given the container name ‘mysqldb’ with ‘–name’ option.
MySql DB needs the root password.
It has been executed with ‘-e’ option.
Since the mysql db image is not available in my current images list,
it pulls it from dockerhub.

You can try to use the same container for your db usage.