Docker tutorials all bind to port 80, and fail on local and remote servers as port 80 is already in use

containersdockerdocker-composeportport80

Trying to wrap my head around all these Docker tutorials, and there is really no explanation around what port 80 is all about. Just, "bind to port 80".

This is the 3rd Docker tutorial I've taken with the same error after running the sample Dockerfile:

Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address
already in use

So, I've understood that port 80 is basically the default port, which would allow my app to run at example.com instead of example.com:80 – for example. My web server, and local machine complain that this port is in use. Of course it is, it's in use by default.

So, why are all these Docker tutorials binding to port 80? I bet they are doing it right, and I am missing something… but, cannot find a clear solution or description.

Here is the tutorial I'm doing: Digital Ocean's Install WordPress with Docker: https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-docker-compose

Sure enough, port 80 fails for me:

webserver:
  depends_on:
    - wordpress
  image: nginx:1.15.12-alpine
  container_name: webserver
  restart: unless-stopped
  ports:
    - "80:80"
  volumes:
    - wordpress:/var/www/html
    - ./nginx-conf:/etc/nginx/conf.d
    - certbot-etc:/etc/letsencrypt
  networks:
    - app-network

Changing this to throws no error, but this means we can only resolve http://example.com:90

ports:
  - "90:80"

What am I missing here? Why are all of these definitions of port 80 failing locally on my Mac and on a remote Digital Ocean Ubuntu8.1 server?

Best Answer

Do you have something else running on port 80? You can try curl localhost:80 or lsof -i :80; you might have Apache or something else running there by default that you'd need to kill.

Related Topic