DEV Community

Cover image for Creating a Docker Image for MySQL Server
Gaurav Kumar
Gaurav Kumar

Posted on

Creating a Docker Image for MySQL Server

Prerequisites

  • Docker must be installed on your machine.
  • You should have a basic understanding of Docker and how it works.

Steps

  1. Open a text editor and copy-paste the provided Dockerfile for MySQL server.

2.Save the file with a suitable name, for example, "Dockerfile-mysql".

3.Open the terminal or command prompt and navigate to the directory where the Dockerfile is saved.

4.Run the following command to build the Docker image:

docker build -t mysql-server -f Dockerfile-mysql .
This command will create a Docker image named "mysql-server" from the Dockerfile.

5.Once the Docker image is built, you can run a container using the following command:

docker run -d -p 3306:3306 --name mysql-container mysql-server

This command will start a container named "mysql-container" from the "mysql-server" image and will map the container's port 3306 to the host's port 3306.

6.You can now connect to the MySQL server from your host machine using any MySQL client, such as MySQL Workbench or phpMyAdmin, by using the following credentials:

  • Host: localhost or 127.0.0.1
  • Port: 3306
  • Username: youruser
  • Password: yourpassword

It's over now! You have at the moment a MySQL server Docker image that you can use for your applications.

Don't forget to catch me up on linkedin
**It's over now! You have at the moment a MySQL server Docker image that you can use for your applications.

**

Top comments (0)