To deploy a MySQL Docker container and start working with the containerized database.

Sonam Kumari Singh
3 min readMar 1, 2023

Docker is one of the most popular tool to containerize the application and consumes very less memory as compared to applications that are lauched directly in Virtual Machines or Bare Metal.

Why do we use enviroment variables in docker ?

Enviroment variable, help to pass the data to the container & configure the mysql container with given credentials.

Steps to setup MySQL with Docker

  1. Pull the docker image

Docker images for MySQL can be pulled from image registry.redhat.io/rhel8/mysql-80:1

> docker pull registry.redhat.io/rhel8/mysql-80:1

Once the container image is fully downloaded on the host, you can see all the downloaded images by using the below command ( # docker images ).

2. Deploy, use the env variable & Start the container with pulled image

> docker run -dit — name <container-name> -P -e MYSQL_USER=user1 -e MYSQL_PASSWORD-mypa55 -e MYSQL_DATABASE=items -e MYSQL_ROOT_PASSWORD=rootps55 registry.redhat.io/rhel8/mysql-80:1

> docker ps

3. Access the container shell

docker exec command allow you to go inside docker container. It’ll give you a bash shell inside <mysql-container-name> container. Now, to access the database and creating some databases , table or insert some data into the database, use the following cammand

> docker exec -it <container-name> /bin/bash

bash-4.4$ > mysql -uroot -p

bash-4.4$ > show databases;

4. Viewing the container logs

docker logs command shows the information loged by a running container.

> docker logs — tail 40 <container-name>

Hope you liked it 😊

--

--

Sonam Kumari Singh

SONAM here! Grateful for your connection! Tech enthusiast exploring new languages, deep into DevOps, with a spotlight on Linux. 😊🚀