Digital Marketing

Allow multiple Docker containers to communicate with each other by Docker network

For example a client application in another Docker container can access the database Server in the server container. 

First, create a Docker network:

docker network create goyun-info-net


When you are creating and starting the server and the client containers, use the --network option to put them on network you created. For example:

docker run --name=mysql1 --network=goyun-info-net -d mysql/mysql-server

docker run --name=myapp1 --network=goyun-info-net -d myapp


The myapp1 container can then connect to the mysql1 container with the mysql1 hostname and vice versa, as Docker automatically sets up a DNS for the given container names

In the following example, we run the mysql client from inside the myapp1 container to connect to host mysql1 in its own container:

docker exec -it myapp1 mysql --host=mysql1 --user=myuser --password


For other networking techniques for containers, see the Docker container networking section in the Docker Documentation.

Comments

Popular posts from this blog

Fixed WSL sshd: no hostkeys available -- exiting

PowerMTA pmta command

How to fix: mv: failed to preserve ownership