docker 端口映射语法

use*_*453 4 port docker

我是 docker 新手,我对以下命令选项专门针对我遇到的命令的作用感到有些困惑。

 --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
Run Code Online (Sandbox Code Playgroud)

Rob*_*ert 6

 docker run -t --name=appname -p 9090:9000 -p 15501:15501/udp -d appname2
Run Code Online (Sandbox Code Playgroud)

Q: --name : appname 是图片的名字吗?

不,它是您正在创建的容器的名称(可选)。

--name string           Assign a name to the container
Run Code Online (Sandbox Code Playgroud)

问: -t :在终端中运行?

-t, --tty             Allocate a pseudo-TTY
Run Code Online (Sandbox Code Playgroud)

问:-d:作为守护进程运行?

有点。这意味着您希望运行与终端分离的容器。

-d, --detach          Run container in background and print container ID
Run Code Online (Sandbox Code Playgroud)

Q: -p : 容器外的人要与端口 9090 通信,他们必须连接端口 9000?

9090:9000表示:9090主机9000上的端口绑定到容器上的端口。要与容器端口通话,外面的人应该与 9090 通话。

-p, --publish list       Publish a container's port(s) to the host (default [])
Run Code Online (Sandbox Code Playgroud)

问:15501 端口也一样,但它是一个 udp 端口​​?

对。


问:appname2:分配给运行图像的名称?

那就是您正在运行的图像。容器是基于它的。


奖金!您可以在此处找到所有这些信息:docker help run

奖金2!自己试试:

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
Run Code Online (Sandbox Code Playgroud)