Skip to content

Instantly share code, notes, and snippets.

@emiel
Created May 11, 2023 15:10
Show Gist options
  • Save emiel/f1493c7cb80aa9d5b82dc499d55c2137 to your computer and use it in GitHub Desktop.
Save emiel/f1493c7cb80aa9d5b82dc499d55c2137 to your computer and use it in GitHub Desktop.
docker: Publish ports

Publish ports on all interfaces. The ports are then accessible from "outside" unless the firewall blocks traffic.

$ docker run -p 80:80 nginx

CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS         PORTS                               NAMES
16f16f77fc90   nginx     "/docker-entrypoint.…"   10 seconds ago   Up 9 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   dreamy_neumann

$ ss -t -n state listening 'sport :80'

Recv-Q                  Send-Q                                   Local Address:Port                                    Peer Address:Port                  Process
0                       4096                                           0.0.0.0:80                                           0.0.0.0:*
0                       4096                                              [::]:80                                              [::]:*

Publish ports on the local interface. The ports are not accessible from the "outside".

$ docker run -p 127.0.0.1:80:80 -p "[::1]:80:80" nginx

CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                  NAMES
756ad0e6f0d8   nginx     "/docker-entrypoint.…"   30 seconds ago   Up 30 seconds   127.0.0.1:80->80/tcp   busy_diffie

$ ss -t -n state listening 'sport :80'
Recv-Q                  Send-Q                                   Local Address:Port                                    Peer Address:Port                  Process
0                       4096                                         127.0.0.1:80                                           0.0.0.0:*
0                       4096                                             [::1]:80                                              [::]:*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment