Search code examples
dockerport

docker port mapping syntax


I am new to docker, and I am a bit confused about what the following command options do specifically for the command I came across.

 --name : appname is the name of the image?
 -t : Run in terminal?
 -d : run as daemon?
 -p : for somebody outside the container to talk to port 9090 they have to connect on port 9000?
 Same for port 15501 but it is a udp port?    
 appname2: name assigned to running image?

 docker run -t --name=appname -p 9090:9000 -p 15501:15501/udp -d appname2

Solution

  •  docker run -t --name=appname -p 9090:9000 -p 15501:15501/udp -d appname2
    

    Q: --name : appname is the name of the image?

    No. It's the name of the container that you are creating (optional).

    --name string           Assign a name to the container
    

    Q: -t : Run in terminal?

    -t, --tty             Allocate a pseudo-TTY
    

    Q: -d : run as daemon?

    Sort of. It means that you want to run your container detached from your terminal.

    -d, --detach          Run container in background and print container ID
    

    Q: -p : for somebody outside the container to talk to port 9090 they have to connect on port 9000?

    9090:9000 means: port 9090 on the host machine binded to port 9000 on the container. To talk to the container port someone outside should talk to 9090.

    -p, --publish list       Publish a container's port(s) to the host (default [])
    

    Q: Same for port 15501 but it is a udp port?

    Right.


    Q: appname2: name assigned to running image?

    That is the image that you are running on. The container is based on top of it.


    Bonus! You can find all of this info here: docker help run

    Bonus 2! Try it yourself:

    docker run -d -it --name my-container alpine sh
    docker inspect my-container
    # See all this funny output. It's all about the container that you've created