Before starting the container, we need to install Docker first. For specific installation, refer to my other article: Docker installation and common commands.

Start a Redis locally

The command to start a Redis locally is as follows:

docker run -d -p 6378:6379 redis
Copy the code

The following table describes the meanings of parameters -d and -p.

1. The meaning of -d parameter

This means that the container is running in the background. Without this parameter, you will see the startup log of Redis, and Redis is closed when you close the window to execute this command. So be sure to start the container with this parameter.

2. Meaning of the -p parameter

This parameter is used to set the port exposure of the container. In the command 637:6379, the last 6379 is the port occupied by the application running in the container. 6378 is the port that corresponds to 6379 in the container to your host. You might be wondering, can’t you just use the port of the application in the container? The answer is no, because the network inside the container is a system of its own, independent, unless some technique is used to map it out.

You may have noticed that container technology involves a lot of operating system and network aspects, yes, so the basics are always important, and if the basics are not solid, this lesson is always to be covered.

MySQL > start MySQL

Start MySQL locally for developers to test, run the following command:

docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
Copy the code

1. Meaning of parameter -e

-e stands for environment variable, and the MYSQL_ROOT_PASSWORD=123456 after it means to set the initial password of MySQL to 123456.

2. Use Navicat to connect to MySQL

This container starts MySQL with the following information:

  • IP address: the address of the host that started the container. Run the ifconfig or IP a command to query the IP address.
  • Port: the port that precedes the information we specify with the -p argument.
  • Account: Directly use root.
  • Password: the 123456 we specified when starting the MySQL container.

Test the effect of the connection, as shown in the following figure, the connection is successful.

Iii. Prospect of follow-up content

1. Common Docker commands

You can refer to my other article: Initial Docker(1) : Docker installation and common commands

2. Basic principles of Docker

Original Docker(3) : How Docker works