Docker Community Forums

Share and learn in the Docker community.

Docker container communication on the same Net, not work

Hi,
I have 3 different docker container (on windows 10) on the same network (core_net), but when use curl on backend

-curl localhost:7000 or curl core:7000

the response is:

“curl: (7) Failed to connect to localhost port 7000: Connection refused”

Why?

Docker commands:

Frontend:

docker run -itd --name dam --net=core_net -p 3000:3000 DAM

Backend:

docker run -itd --name core --net=core_net -p 6000:6000 -p 7000:7000 -p 8000:8000 -p 9000:9000 SG

Database:

docker run --name mongodb -p 27017:27017 -d mongo:3

These is the dockerfile:

Frontend:
FROM node:4.5.0
# Create app directory
RUN mkdir -p /DAM
WORKDIR /DAM

# Install app dependencies
COPY package.json /DAM
RUN npm install
RUN npm install gulp -g
RUN echo '{ "allow_root": true }' > /root/.bowerrc
RUN npm install bower -g

# Bundle app source
COPY . /DAM

ENV PORT 3000 3001
EXPOSE  $PORT

CMD ["gulp", "serve"]

and

Backend:
FROM node:4.5.0

RUN npm install nodemon -g

# Create app directory
RUN mkdir -p /SG
WORKDIR /SG

# Install app dependencies
COPY package.json /SG
RUN npm install

# Bundle app source
COPY . /SG

ENV PORT 6000 7000 8000 9000
EXPOSE  $PORT

CMD ["npm", "start"]

Inside container the ping works and the inspect is this:

$ docker network inspect core_net                                                                           	
                                                                                                           
   {                                                                                                       
       "Name": "core_net",                                                                                 
       "Id": "1f9e5426abe397d520360c05c95fee46fe08c98fe5c474c8b52764e491ea23e7",                           
       "Scope": "local",                                                                                   
       "Driver": "bridge",                                                                                 
       "EnableIPv6": false,                                                                                
       "IPAM": {                                                                                           
           "Driver": "default",                                                                            
           "Options": {},                                                                                  
           "Config": [                                                                                     
               {                                                                                           
                   "Subnet": "172.18.0.0/16",                                                              
                   "Gateway": "172.18.0.1"                                                                 
               }                                                                                           
           ]                                                                                               
       },                                                                                                  
       "Internal": false,                                                                                  
       "Containers": {                                                                                     
           "3d3b8780fba2090b1c2feaddf2e035624529cf5474ad4e6332fe7071c0acbd25": {                           
               "Name": "core",                                                                             
               "EndpointID": "f0a6882e690cf5a7deedfe57ac9b941d239867e3cd58cbdf0ca8a8ee216d53a9",           
               "MacAddress": "02:42:ac:12:00:04",                                                          
               "IPv4Address": "172.18.0.4/16",                                                             
               "IPv6Address": ""                                                                           
           },                                                                                              
           "bb6a6642b3a7ab778969f2e00759d3709bdca643cc03f5321beb9b547b574466": {                           
               "Name": "dam",                                                                              
               "EndpointID": "b42b802e219441f833d24971f1e1ea74e093f56e28126a3472a44750c847daa4",           
               "MacAddress": "02:42:ac:12:00:02",                                                          
               "IPv4Address": "172.18.0.2/16",                                                             
               "IPv6Address": ""                                                                           
           },                                                                                              
           "cf8dd2018f58987443ff93b1e84fc54b06443b17c7636c7f3b4685948961ba3f": {                           
               "Name": "mongodb",                                                                          
               "EndpointID": "be02d784cbd46261b7a53d642102887cafa0f880c8fe08086b9cc026971ea1be",           
               "MacAddress": "02:42:ac:12:00:03",                                                          
               "IPv4Address": "172.18.0.3/16",                                                             
               "IPv6Address": ""                                                                           
           }                                                                                               
       },                                                                                                  
       "Options": {},                                                                                      
       "Labels": {}                                                                                        
   }                                                                                                       

Commnication between mongodb and core work but between dam and core not work.
what’s the problem?