When I try to connect to the container from itself using curl -v localhost, I get:
* Trying 127.0.0.1:80...
* TCP_NODELAY set
* connect to 127.0.0.1 port 80 failed: Connection refused
* Trying ::1:80...
* TCP_NODELAY set
* Immediate connect fail for ::1: Address not available
* Trying ::1:80...
* TCP_NODELAY set
* Immediate connect fail for ::1: Address not available
* Failed to connect to localhost port 80: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 80: Connection refused
I mention that I don't want to connect neither from the container to the host, nor from the host to the container (I could only find information about these 2 use cases) but from inside the container to the container itself.
Here is my docker-compose.yml:
services:
php:
build:
context: .
dockerfile: docker/php/Dockerfile
ports:
- '8000:80'
volumes:
- ./app:/var/www/html
Just in case, I mention that I'm using the image php:7.3-fpm-alpine.
I also tested with curl -v php (with the name of the container), I got:
* Trying 172.18.0.5:80...
* TCP_NODELAY set
* connect to 172.18.0.5 port 80 failed: Connection refused
* Failed to connect to content_php port 80: Connection refused
* Closing connection 0
curl: (7) Failed to connect to content_php port 80: Connection refused
While ping php is OK:
PING php (172.18.0.5): 56 data bytes
64 bytes from 172.18.0.5: seq=0 ttl=64 time=0.262 ms
I also tested by adding EXPOSE: 80 in docker-compose.yml, I got the same result.
I also tested with curl localhost:8000, I got the same result with port 8000.
I noticed with docker ps there is a default port set on 9000:
PORTS
9000/tcp, 0.0.0.0:8000->80/tcp
When I execute curl localhost:9000 and I get:
curl: (56) Recv failure: Connection reset by peer
What am I missing to be able to connect to the container from itself?
docker-compose up. I enter in the container withdocker-compose exec -u root php bash.