• Uncategorized

About linux : When-mapping-host-ports-to-container-ports-the-host-ports-are-only-visible-after-restarting-docker-engine

Question Detail

When I run my docker container, I cannot always access the host exposed ports. Take this simple example of a couchdb service in a docker compose file.

version: '3.8'
    container_name: couch
    image: couchdb:latest
      - ./.env
      - 5984
      - "5984:5984"
      - ../database/data:/opt/couchdb/data

I would expect the port 5984 to be exposed on my host machine, but when I run curl there is no result. It just gets stuck but the container is up and running. If I exec into the container I can run that same curl command and get the expected couchdb welcome message.

The interesting part:
If I restart docker by running systemctl restart docker then the container will run as expected for one run and give me the welcome message from the host curl. If I stop the container with Ctr+C and rerun the build with docker compose up --build couch it will not expose the port again until I restart the docker service. This is not related to couchdb and happens with all of my docker containers atm.

How is this possible?

Further Infos
A similar phenomenon happens when installing the pip python dependencies on another service. It will say it can’t connect to the repo but after restarting docker it will always work.

I’m running Ubuntu (20.04.3 LTS) on a remote server through ssh. All of this works fine on my local laptop btw. (Mac M1 Monterey 12.0.1).
Docker Engine Version (20.10.12)

Question Answer

No answer for now.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.