Docker to run new container – list of all mapped ports?

When running a new container, we specify a port RUN_PORT:EXPOSED_PORT to map with the host machine. This will fail if RUN_PORT is already used.

So my question is how to list all the mapped port – so that we can pick up the port number out of the list.

  • Running multiple docker containers in same host
  • sbt-docker difference between add and addRaw
  • Copy files and create symlink from a shared volume on Docker on container start
  • Using SSL on nginx in a Docker container hosted on Jelastic
  • Docker (NGINX, PHP, mySQL) and Windows - File Permissions
  • How to mount private SSH key to Docker for Windows container?
  • p.s.

    I’m using Ubuntu 16.04

  • How to email from Wordpress in Docker container?
  • Flock command - “waiting” threads
  • Can multiple Docker containers run using the same host/port?
  • unable to find user root: no matching entries in passwd file
  • How to change docker0 setting in CoreOS?
  • Docker cannot run on build when running container with a different user
  • 2 Solutions collect form web for “Docker to run new container – list of all mapped ports?”

    Do the following command

    sudo netstat -tlnp | grep ":RUN_PORT"

    Replace RUN_PORT with the actual port to see which application is blocking it.

    Listing all tcp ports being used (for listening) can be seen with:

    netstat -lnt

    Looking up what is using a single port can be done with a netstat and grep, or if you have lsof installed:

    sudo lsof -i :80 # shows the process using port 80

    Starting a docker container on a random available port mapped to port 80 inside the container:

    docker run -p 80 -n container_name your_container

    Looking up what random port docker used in the above command on the host (this includes what IP interfaces it’s attached to, or for all interfaces, which is the default):

    docker port container_name 80
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.