`docker run` publishes ports correctly but `compose up` and `stack deploy` don't

Hi!

Is there any additional configuration necessary to get networking to work on docker stack and docker compose in ubuntu 20.04?

I’m trying to run a stack with our applications on a server with Ubuntu 20.04 on it, but even though I indicate the port mapping correctly in the docker-compose.yml file, ports are not listening correctly and the browser gets no answer. I’ve tried with both the nginx and portainer official images.

If I run docker run -p 80:80 -p 443:443 nginx, I can then access http://<my_server_ip> and see the nginx welcome page. The same goes for portainer: docker run -p 80:9000 -p 443:9443 portainer/portainer-ce and http://<my_server_ip> shows the portainer login page.

But, when I try to do the same with compose:

# docker-compose.yaml for nginx
version: "3"
services:
  nginx:
    image: nginx
    ports:
      - 80:80
      - 443:443
# docker-compose.yaml for portainer
version: "3"
services:
  portainer:
    image: portainer/portainer-ce
    ports:
      - 80:9000
      - 443:9443

I get no response in the browser when I go to http://<my_server_ip>. I’ve tried both with docker-compose up and docker stack deploy -c docker-compose.yaml portainer|nginx (used nginx in the first experiment and portainer in the second one).

Any help would be very much appreciated as this issue has come at quite a critical time :smiley:

It’s also happening to me on Debian 10

This works for me, with docker compose up in the latest Docker Desktop on an Intel Mac. Going to http://localhost shows me an Nginx Welcome page.

The other one works too, redirecting me to http://localhost/#!/init/admin.

Thanks a lot for your response Arjan :slight_smile: in the end it turns out that on Debian 10 it did indeed work. I’ve left the task of finding out what was happening on Ubuntu 20.04 to greater minds than mine :smiley:

Did anyone solve this problem? I have exactly the same problem with ubuntu 22.04 server.
I can reach the container dashboard on the published port via localhost:port with a cli-browser on the docker host. Using ip:port with the same browser or trying to acces from a remote host results in time out.