Guangning Yu's Blog
Home
Code
Data
Setup
Industry
MachineLearning
Archive
Access another container in Docker
2019-02-26 14:28:04
|
Docker
# Steps 1. Create a network named "test" ``` docker network create test ``` 2. Create two containers using the network ``` docker run --name c1 --network "test" --rm --entrypoint tail mongo -f docker run --name c2 --network "test" --rm --entrypoint tail mongo -f ``` 3. Enter one container to ping the other and it will work ``` docker exec -it c1 bash ``` ``` apt-get install iputils-ping # install command ping ``` ``` root@79568c5ce391:/usr/src/app# ping c2 PING c2 (172.18.0.3) 56(84) bytes of data. 64 bytes from c2.test (172.18.0.3): icmp_seq=1 ttl=64 time=0.137 ms 64 bytes from c2.test (172.18.0.3): icmp_seq=2 ttl=64 time=0.221 ms 64 bytes from c2.test (172.18.0.3): icmp_seq=3 ttl=64 time=0.232 ms ... ``` # Notes Using default network or "bridge" network does not work: ``` docker run --name c1 --rm --entrypoint tail web_scraper:v1 -f docker run --name c2 --rm --entrypoint tail web_scraper:v1 -f ``` ``` docker run --name c1 --network "bridge" --rm --entrypoint tail web_scraper:v1 -f docker run --name c2 --network "bridge" --rm --entrypoint tail web_scraper:v1 -f ```
Previous:
Setup SQL Server and pyodbc
Next:
Publish or expose port (-p, --expose)