What is the method for starting MySQL in Docker?
The way to start MySQL using Docker is by using Docker commands or a Docker Compose file.
- Start MySQL using Docker command.
- Open the terminal or command prompt.
- Run the following command to pull the MySQL image and start the container: docker run –name mysql-container -e MYSQL_ROOT_PASSWORD=
-p :3306 -d mysql:latest In this command, mysql-container is the container’s name,
is the host port number, and is the root user password for MySQL. - Wait for some time, the MySQL container will start and run.
- Start MySQL using Docker Compose.
- Create a file named docker-compose.yml and add the following content to the file:
version: ‘3’
services:
mysql:
image: mysql:latest
container_name: mysql-container
environment:
– MYSQL_ROOT_PASSWORD=ports:
–:3306 Here,
is the root password for MySQL, and is the host port number. - Open the terminal or command prompt.
- In the directory containing the docker-compose.yml file, run the following command to start the MySQL container: docker-compose up -d
The -d option is used to run the container in the background.
- After waiting for some time, the MySQL container will start up and run.
Whether using Docker commands or Docker Compose, the MySQL container will start on a specified port on the local host and can be connected to using the MySQL client.