Vincent Ascosi's Blog

docker

#100DaysToOffload #docker #linux

Why am I writing this?

A friend needed help with exposing ports with docker containers, so I thought I would write about it.

Why do you need to exposing ports?

So docker container are contained to their own virtual network, furthermore exposing ports is like port forwarding on a router. This prevents port collision between docker services.

How do i do this?

To expose a port number, use the docker command with the option -p 8080:80. In this example the 8080 is the host facing port, while the 80 is the port number used by the app inside the docker container.

To do the same with docker compose:

ports:
      - "8080:80"