$ docker network create my_web_net $ docket network create my_api_net $ docker network ls
sample output:
NETWORK ID NAME DRIVER SCOPE 0a34ec3a4f58 bridge bridge local 5452c8e97607 host host local 5046472b737d my_api_net bridge local 11ac61aabd27 my_web_net bridge local d6a1ef964756 none null local
Note: MySQL container does not need to expose (or publish) port 3306 to the host. We only need to expose Apache container.
$ docker container run -d --name my_mysql --network my_web_net -e MYSQL_RANDOM_ROOT_PASSWORD=yes mysql:5.7 $ docker container run -d --name my_apache --network my_web_net -p 80:80 httpd:alpine $ docker network inspect my_web_net
Note: MongoDB container does not need to expose (or publish) port 27017 to the host. We only need to expose Nginx container.
$ docker container run -d --name my_mongo --network my_api_net -e MYSQL_RANDOM_ROOT_PASSWORD=yes mysql:5.7 $ docker container run -d --name my_nginx --network my_api_net -p 8081:80 nginx:alpine $ docker network inspect my_api_net
$ docker container exec -it my_apache sh
within the 'my_apache', and try to ping 'my_mysql' and 'my_mongo'
/# ping my_mysql /# ping my_mongo
Create temporary alpine container in 'my_web_net' just to ping 'my_mysql' and remove the container immediatly
$ docker container run -it --rm --network my_web_net alpine ping my_mysql