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'
services:
couch:
container_name: couch
image: couchdb:latest
env_file:
- ./.env
expose:
- 5984
ports:
- "5984:5984"
volumes:
- ../database/data:/opt/couchdb/data
I would expect the port 5984 to be exposed on my host machine, but when I run curl 127.0.0.1:5984
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)