Running a MySQL Docker image on a user-defined bridge network
Whenever we run a Docker image to create and boot up a container, it uses the default bridge network, which Docker creates during installation. To run an image on a specific network, which may be either user-defined or one of the other two networks that Docker creates automatically, host or none, we have to provide the additional --net
flag with the value as the network name as part of the docker run
command.
In this recipe, we will run a MySQL image on the user-defined bridge network that we created in the previous recipe, passing the --net
flag value as my-bridge-network
.
How to do it…
Execute the docker run
command to create and run a MySQL Docker container from the mysql:latest
image, assigning the container name as mysql-container
using the --name
flag, as follows:
$ docker run --net=my-bridge-network -p 3306:3306 --name mysql-container -e MYSQL_ROOT_PASSWORD=my-pass -d mysql:latest c3ca3e6f253efa40b1e691023155ab3f37eb07b767b1744266ac4ae85fca1722...