title: When mapping host ports to container ports, the host ports are only visible after restarting docker engine
body: <p>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.</p>
  <pre class="lang-yaml prettyprint-override"><code>version: '3.8'
  services:
     
    couch:
      container_name: couch
      image: couchdb:latest
      env_file:
        - ./.env
      expose:
        - 5984
      ports:
        - &quot;5984:5984&quot;
      volumes:
        - ../database/data:/opt/couchdb/data
  
  </code></pre>
  <p>I would expect the port 5984 to be exposed on my host machine, but when I run <code>curl 127.0.0.1:5984</code> 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.</p>
  <p><strong>The interesting part:</strong>
  If I restart docker by running <code>systemctl restart docker</code> 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 <code>Ctr+C</code> and rerun the build with <code>docker compose up --build couch</code> 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.</p>
  <p>How is this possible?</p>
  <p><strong>Further Infos</strong>
  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.</p>
  <p>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)</p>