Updated on 2024-06-17 GMT+08:00

Using Portainer to Deploy a MySQL Container

This section uses the MySQL container as an example to describe how to use Portainer to visualize Docker management.

Creating a MySQL Container

  1. Choose Containers in the left navigation pane and click Add container.

  2. Specify MySQL container parameters.
    • Name: user-defined container name.
    • Image: container image name. For example, if you set this parameter to mysql:5.7, the system automatically pulls the MySQL5.7 container image from Docker Hub.
    • ③ Click publish a new network port and add port 3306 to ensure that the MySQL database can be accessed.
    • Env: environment variables.
      • MYSQL_ROOT_PASSWORD: password of the root user of the database. This parameter is mandatory. It is used for logging in to the MySQL container. Keep the password secure.

        Ensure that the MYSQL_ROOT_PASSWORD parameter name is correctly entered, or the database cannot be connected.

      • MYSQL_DATABASE: name (such as wordpress) of the database which is automatically created in the value row after the MySQL container is created. This parameter is optional.
    • Restart policy: You are advised to select Always so that the container is always automatically restarted when it is stopped.

  3. Click Deploy the container to create a MySQL container.

Connecting to the MySQL Container

  1. Return to the container list and click in the MySQL container row.

  2. On the displayed page, click Connect to connect to the container.
  3. Run the following command to log in to the MySQL database:

    mysql -uroot –p123456, in which 123456 is the value of MYSQL_ROOT_PASSWORD.