I wanted a oneliner to try out different PHP versions, and thought the following should work:
docker run -p 8000:80 -v "$(pwd):/var/www/html" php:7.4-apache
While I can connect to the server on port 80 from inside the container, from outside accessing port 8000 with curl hangs for a while then prints:
$ curl -I http://localhost:8000/
curl: (56) Recv failure: Connection reset by peer
The first thing I checked was if 80 was exposed and published and it was:
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c24ac2f9a567 php:7.4-apache "docker-php-entrypoi…" 3 seconds ago Up 3 seconds 0.0.0.0:8000->80/tcp, :::8000->80/tcp optimistic_bose
$ docker history php:7.4-apache
IMAGE CREATED CREATED BY SIZE COMMENT
20a3732f422b 17 months ago /bin/sh -c #(nop) CMD ["apache2-foreground"] 0B
<missing> 17 months ago /bin/sh -c #(nop) EXPOSE 80 0B
If I add a docker-compose.yml
with the following contents:
services:
web:
image: php:7.4-apache
ports:
- 8000:80
volumes:
- .:/var/www/html
Then it works just fine, even though this should be functionally identical to the oneliner. What am I doing wrong?