Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 5952

Cannot curl docker container from alpine container, but can with ubuntu container, all in same docker compose network

$
0
0

Earlier today I was attempting to set up a docker compose file containing a few different services, one of which was running nginx:latest. One of my other services was running on alpine:latest, and no matter what I tried I could not successfully curl the nginx service from the alpine container, and keep seeing Failed to connect to nginx port 80 errors from curl. Curling the nginx service from containers running other images seems to workout just fine.

In an attempt to recreate the issue, I have reduced the docker-compose.yml file as much as possible, and came up with this:

services:  alpine-test:    build:      dockerfile: Dockerfile.alpine    command: sleep 3600    networks:      - test-network  ubuntu-test:    build:       dockerfile: Dockerfile.ubuntu    command: sleep 3600    networks:      - test-network  nginx:    image: nginx:latest    ports:      - "8080:80"    networks:      - test-networknetworks:  test-network:    driver: bridge

Dockerfile.ubuntu:

FROM ubuntu:latestRUN apt update -y && apt install -y curl

Dockerfile.alpine:

FROM alpine:latestRUN apk update && apk add curl

I am spinning up the compose project with this command:

docker compose -f docker-compose.test.yaml up --force-recreate

Curling the nginx service from the ubuntu service:

docker exec proj-local-ubuntu-test-1 curl -vv http://nginx

Output:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 172.27.0.3:80...* Connected to nginx (172.27.0.3) port 80 (#0)> GET / HTTP/1.1> Host: nginx> User-Agent: curl/7.81.0> Accept: */*>* Mark bundle as not supporting multiuse< HTTP/1.1 200 OK< Server: nginx/1.27.0< Date: Fri, 14 Jun 2024 23:52:50 GMT< Content-Type: text/html< Content-Length: 615< Last-Modified: Tue, 28 May 2024 13:22:30 GMT< Connection: keep-alive< ETag: "6655da96-267"< Accept-Ranges: bytes<{ [615 bytes data]100   615  100   615    0     0   820k      0 --:--:-- --:--:-- --:--:--  600k* Connection #0 to host nginx left intact<!DOCTYPE html><html><head><title>Welcome to nginx!</title><style>html { color-scheme: light dark; }body { width: 35em; margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif; }</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.</p><p>For online documentation and support please refer to<a href="http://nginx.org/">nginx.org</a>.<br/>Commercial support is available at<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p></body></html>

Curling the nginx service from the alpine service:

docker exec proj-local-alpine-test-1 curl -vv http://nginx

Output:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Host nginx:80 was resolved.* IPv6: (none)* IPv4: 192.168.1.1*   Trying 192.168.1.1:80...  0     0    0     0    0     0      0      0 --:--:--  0:02:12 --:--:--     0* connect to 192.168.1.1 port 80 from 172.27.0.3 port 54744 failed: Operation timed out* Failed to connect to nginx port 80 after 132953 ms: Couldn't connect to server  0     0    0     0    0     0      0      0 --:--:--  0:02:12 --:--:--     0* Closing connectioncurl: (28) Failed to connect to nginx port 80 after 132953 ms: Couldn't connect to server

The containers all seem to be correctly sharing the same network:

[    {"Name": "cmapp-local_test-network","Id": "5a258b6b903fec157391704554845314423dd261614cbbffb5feb178edbfb0cb","Created": "2024-06-14T16:35:02.946998948-07:00","Scope": "local","Driver": "bridge","EnableIPv6": false,"IPAM": {"Driver": "default","Options": null,"Config": [                {"Subnet": "172.27.0.0/16","Gateway": "172.27.0.1"                }            ]        },"Internal": false,"Attachable": false,"Ingress": false,"ConfigFrom": {"Network": ""        },"ConfigOnly": false,"Containers": {"1a481a82e1aae822cacca707a997fca13d2a15a7a2ba9acaa2f67716f432301a": {"Name": "cmapp-local-alpine-test-1","EndpointID": "cda6b08db448c918e4d3763cbc1d6bb628ee592f9dc6c61d2cb5e2233fb7ffc0","MacAddress": "02:42:ac:1b:00:03","IPv4Address": "172.27.0.3/16","IPv6Address": ""            },"78416ae61c2c86dec2b978ba07dcaf7dc96b17fcd6b608ef21a60b55a90a05d6": {"Name": "cmapp-local-ubuntu-test-1","EndpointID": "bf56252dd5a4b5ebd6cdab1f2c3b8653d64e5ced1d571b70c00caef2fc8722b8","MacAddress": "02:42:ac:1b:00:04","IPv4Address": "172.27.0.4/16","IPv6Address": ""            },"a4e95ed049894930573c8d2713a832c27e5f8ef3d14196298e6c99c786aed25a": {"Name": "cmapp-local-nginx-1","EndpointID": "74f816a26ff1bafc5936fe67d2e4c750ca1fdaaeedb879ea01a9aec5225e4e35","MacAddress": "02:42:ac:1b:00:02","IPv4Address": "172.27.0.2/16","IPv6Address": ""            }        },"Options": {},"Labels": {"com.docker.compose.network": "test-network","com.docker.compose.project": "cmapp-local","com.docker.compose.version": "2.27.1"        }    }]

The resolv.conf files from both the ubuntu and alpine containers look identical, presumably because docker generates them:

Ubuntu resolv.conf

# Generated by Docker Engine.# This file can be edited; Docker Engine will not make further changes once it# has been modified.nameserver 127.0.0.11search lanoptions edns0 trust-ad ndots:0# Based on host file: '/etc/resolv.conf' (internal resolver)# ExtServers: [host(127.0.0.53)]# Overrides: []# Option ndots from: internal

Alpine resolv.conf

# Generated by Docker Engine.# This file can be edited; Docker Engine will not make further changes once it# has been modified.nameserver 127.0.0.11search lanoptions edns0 trust-ad ndots:0# Based on host file: '/etc/resolv.conf' (internal resolver)# ExtServers: [host(127.0.0.53)]# Overrides: []# Option ndots from: internal

Running nslookup in the alpine container returns some strange results:

Server:         127.0.0.11Address:        127.0.0.11:53Non-authoritative answer:Non-authoritative answer:Name:   nginx.lanAddress: 192.168.1.1

whereas the nslookup output in the ubuntu container are more what I was expecting:

Server:         127.0.0.11Address:        127.0.0.11#53Non-authoritative answer:Name:   nginxAddress: 172.27.0.2

Any help on this would be greatly appreciated. Thank you.


Viewing all articles
Browse latest Browse all 5952

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>