Docker Compose Port Not Exposed?

vn flag

I have a simple Python based web server running in a container set up with docker compose that exposes port 8080.

When I docker-compose up the services it reports the ports are exposed but the port is not exposed externally.

What should I look at diagnosing next?

Here's a typical run

➜  demo04 sudo docker-compose up -d
Recreating leagueweb_database ... done
Recreating leagueweb_server   ... done

The Python web server (using CherryPy) reports it has started OK and opened port 8080.

leagueweb_server | [25/Jan/2022:11:27:21] ENGINE Serving on

Docker reports that it is forwarding port 8080

➜  demo04 sudo docker-compose ps
       Name                     Command                  State                              Ports
leagueweb_database   / mysqld            Up (healthy)>3306/tcp,:::3306->3306/tcp, 33060/tcp
leagueweb_server     ./ database: ...   Up   >8080/tcp,:::8080->8080/tcp

Testing this from a remote PC I can see that although port 3306 is open externally - port 8080 is not.

PS C:> Test-NetConnection -Port 3306
RemoteAddress    :
RemotePort       : 3306
TcpTestSucceeded : True

PS C:> Test-NetConnection -Port 8080
WARNING: TCP connect to ( : 8080) failed

The firewall is turned off

➜  demo04 sudo ufw status
Status: inactive

This is the docker compose file

version: '3'

        # Install Python and required libraries with a Dockerfile
            context: .
            dockerfile: leagueweb.dockerfile
        restart: unless-stopped
        container_name: leagueweb_server
        # Don't start up until the database is started
            - database
        # Expose HTTP port 
            - "8080:8080"

        # Mount the leagueweb code and resources
            - "/home/testuser/demo04/code:/leagueweb"
        # Start the server only once the database is running
        command: ["./", "database:3306", "--", "python", "-u", "/leagueweb/"]

        # Use MySQL 5.7 as the database
        image: mysql/mysql-server:5.7
        restart: unless-stopped
        container_name: leagueweb_database

        # Set environment variables to set initial database set-up
            - "MYSQL_ROOT_PASSWORD=root"
            - "MYSQL_USER=leagueweb"
            - "MYSQL_PASSWORD=********"
            - "MYSQL_DATABASE=leagueweb01"
        # Uncomment to expose the MySQL database externally on port 3306 for 
        # testing 
            - "3306:3306"

        # Mount init.sql file to automatically run and create tables for us.
        # everything in docker-entrypoint-initdb.d folder is executed as 
        # soon as container is up and running.
            - "/home/testuser/demo04/db:/docker-entrypoint-initdb.d"
cn flag

This looks like a problem:

ENGINE Serving on

Looks like you need to reconfigure your python server to listen on, not

evoelise avatar
vn flag
Thanks. Can't believe I didn't see that - it was starting me in the face. Looks like I had got too focused on thinking it was a container issue.
cn flag
Happens to us all!
Mathias avatar
br flag
Oh man, thank you so much. I was going crazy why I can't reach the exposed port.

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.