Deploying MySQL on Linux with Docker { "Type": "volume", "Name": "4f2d463cfc4bdd4baebcb098c97d7da3337195ed2c6572bc0b89f7e845d27652", "Source": "Destination": "/var/lib/mysql", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ], ... Another way to preserve data is to bind-mount a host directory using the  --mount  option when creating the container. The same technique can be used to persist the configuration of the server. The following command creates a MySQL Server container and bind-mounts both the data directory and the server configuration file: The output shows that the source folder  /var/lib/docker/ volumes/4f2d463cfc4bdd4baebcb098c97d7da3337195ed2c6572bc0b89f7e845d27652/_data , in which data is persisted on the host, has been mounted at  /var/lib/mysql , the server data directory inside the container. docker run --name=mysql1 \ --mount type=bind,src= /path-on-host-machine/my.cnf ,dst=/etc/my.cnf \ --mount type=bind,src= /path-on-host-machine/datadir ,dst=/var/lib/mysql \ -d mysql/mysql-server: tag The command mounts  path-on-host-machine/my.cnf  at  /etc/my.cnf  (the server configuration file inside the container), and  path-on-host-machine/datadir  at  /var/lib/mysql  (the data directory inside the container). The following conditions must be met for the bind-mounting to work: •The configuration file  path-on-host-machine/my.cnf  must already exist, and it must contain the specification for starting the server using the user  mysql : [mysqld] user=mysql You can also include other server configuration options in the file. •The data directory  path-on-host-machine/datadir  must already exist. For server initialization to happen, the directory must be empty. You can also mount a directory prepopulated with data and start the server with it; however, you must make sure you start the Docker container with the same configuration as the server that created the data, and any host files or directories required are mounted when starting the container. Running Additional Initialization Scripts If there are any  .sh  or  .sql  scripts you want to run on the database immediately after it has been created, you can put them into a host directory and then mount the directory at  /docker-entrypoint- initdb.d/  inside the container. For example: docker run --name=mysql1 \ --mount type=bind,src= /path-on-host-machine/scripts/ ,dst=/docker-entrypoint-initdb.d/ \ -d mysql/mysql-server: tag Connect to MySQL from an Application in Another Docker Container By setting up a Docker network, you can allow multiple Docker containers to communicate with each other, so that a client application in another Docker container can access the MySQL Server in the server container. First, create a Docker network: 189