Using MySQL docker image

Probably the most popular open-source database applications out there is MySQL. Though this might not be your preferred one as they have changed their licensing model after they were bought by Oracle.

For our purpose, we will be using MySQL.

Prerequisites

During the design stage, we need to determine a few things.

What are we using this for?

We will be using this database as the backend for a WordPress website hosted on another container in the same host.

Where are we storing the data

The image defaults to storing the database within the container. This is fine for our application.

If your needs are different, you can choose to locate the data store in the host machine's filesystem. This can be specified in the run command.

Installing MySQL docker image

You can launch a MySQL database using:

# docker run --rm --name mydbsvr-1 -e MYSQL_ROOT_PASSWORD='my-secret-password' -p 3306:3306 -d mysql:latest

This will launch a mysql server and detach, or daemonise. You can confirm this by checking:

# docker ps

You should see mydbsvr-1 on the list.

Connecting to the database

You will need the mysql client installed on your machine. You can connect using:

# mysql -h 127.0.0.1 -P 3306 -u root -p