Docker Community Forums

Share and learn in the Docker community.

When docker-compose start, all network not working


(Wyntau) #1

when docker-compose up -d, the host can’t ping success, and outer browser can’t access to the host.

my docker-compose.yml is below

version: "2" 
services: 
  nginx: 
    image: nginx:stable-alpine 
    container_name: nginx
    ports: 
      - "80:80" 
    networks:
      - demo
    volumes:
      - ./nginx-conf.d:/etc/nginx/conf.d:ro
networks: 
  demo:
    driver: bridge

and my nginx-conf.d only has a conf

server {
  listen 80;
  location / {
    return 404;
  }
}

if the docker-compose didn’t up, I can ping the host success

➜  ~ ping 10.4.233.155
PING 10.4.233.155 (10.4.233.155): 56 data bytes
64 bytes from 10.4.233.155: icmp_seq=0 ttl=56 time=3.463 ms
64 bytes from 10.4.233.155: icmp_seq=1 ttl=56 time=2.517 ms
^C
--- 10.4.233.155 ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 2.517/2.990/3.463/0.473 ms

but If the docker-compose up, I cannot ping again

➜  ~ ping 10.4.233.155
PING 10.4.233.155 (10.4.233.155): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
^C
--- 10.4.233.155 ping statistics ---
5 packets transmitted, 0 packets received, 100.0% packet loss

But If I use the host’s own curl, the result is correct.

 ➜  confluence git:(master) ✗ curl -I http://localhost:80
HTTP/1.1 404 Not Found
Server: nginx/1.12.2
Date: Wed, 02 May 2018 07:39:17 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

 ➜  confluence git:(master) ✗ curl -I http://127.0.0.1:80
HTTP/1.1 404 Not Found
Server: nginx/1.12.2
Date: Wed, 02 May 2018 07:39:25 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

 ➜  confluence git:(master) ✗ curl -I http://10.4.233.155:80
HTTP/1.1 404 Not Found
Server: nginx/1.12.2
Date: Wed, 02 May 2018 07:39:37 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

If I do not use docker-compose, just run

docker run --rm --name nginx -v /path/to/conf.d:/etc/nginx/conf.d nginx:stable-alpine

the host self and outer browser can access nginx both.

Can anyone help me?