Score:0

Docker container port mapping 80:80 only works on localhost but not from external access?

id flag

Logged in my intranet server via SSH on IP 10.10.245.209 (port 22 of course)

Created a docker-compose.yml:

version: '3.8'
services:
  php-apache-environment:
    container_name: php-apache
    image: php:8.0-apache
    volumes:
      - ./php/src:/var/www/html/
    ports:
      - 80:80

And in ./php/src I have index.php:

<?php
echo 123+123;

I use docker-compose up -d in the current directory, and the container is successfully started:

CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS                    PORTS                               NAMES
9795a5fdd59f   php:8.0-apache           "docker-php-entrypoi…"   19 minutes ago   Up 19 minutes             0.0.0.0:80->80/tcp, :::80->80/tcp   php-apache

Now if I use lynx http://localhost or lynx http://127.0.0.1, it's correctly returning:

246

As the web page. But when I try to access the server http://10.10.245.209 in Chrome, it keeps circling for a few seconds and then nothing (ERR_EMPTY_RESPONSE).

lsof -i:80 results:

COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 24074 root    4u  IPv4 129863      0t0  TCP *:http (LISTEN)
docker-pr 24081 root    4u  IPv6 131383      0t0  TCP *:http (LISTEN)

According to docs and some searches in Google, everything I did was correct?

What could be wrong here?

Itai Ganot avatar
gl flag
Did you open port 80 in the firewall?
djdomi avatar
za flag
I would use a other port as 80 on the container due I had a fault in the mapping of the container, however the question is what `lsof -I :80` is telling
id flag
@Itai How do I know if port 80 is open?
id flag
`lsof -I :80` gives me `lsof: illegal option character: I`
id flag
@djdomi I've updated the output of `lsof -i:80` in the question.
id flag
@djdomi By `a other port as 80 on the container`, do you mean the container port or the host port?
djdomi avatar
za flag
I would use port 8080 for the host, since port 80 seems to be fixed used in the container
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.