我执行如下所示的docker run命令
docker run -it --rm --net=host tensorrtserver_client
执行此命令时,我看到命令提示符已更改
来自
Rajini @ server_name
到
root @ server_name:/#
上面命令中的' it '不代表交互式吗?
您能告诉我这里发生了什么吗?
如果它使用图像“ tensorrtserver_client”启动容器,那么它不应该进入容器提示吗?并显示类似 container_id的代码:#?
请找到指向dockerfile的链接以及我遵循的过程
https://github.com/NVIDIA/tensorrt-inference-server/blob/master/Dockerfile.client
https://docs.nvidia.com/deeplearning/sdk/tensorrt-inference-server-guide/docs/quickstart.html
答案 0 :(得分:2)
a)如果您使用默认的docker0
网络且未指定容器的--hostname
,则其行为类似于下一个:
shubuntu1@shubuntu1:~$ docker run -it ubuntu /bin/bash
root@0ad9bd6bfc90:/#
b)如果使用默认的docker0
并指定--hostname
的容器,它将类似于:
shubuntu1@shubuntu1:~$ docker run -it --hostname=abc ubuntu /bin/bash
root@abc:/#
c)如果您不使用docker0
,请根据您的情况使用--net=host
,它将共享主机网络。然后,如果您未指定--hostname
,它将为您的容器提供一个隐式主机名,该名称与docker主机名相同:
shubuntu1@shubuntu1:~$ docker run -it --net=host ubuntu /bin/bash
root@shubuntu1:/#
因此,c)
上方表示您已经在容器提示中。
答案 1 :(得分:2)
您获得了 root @ server_name:/#,因为/bin/bash
是tensorrtserver_client
图像的默认入口点。
我尝试了以下步骤:
[node1] (local) root@192.168.0.38 ~/tensorrt-inference-server
$ docker run -it --rm --net=host tensorrtserver_client
root@node1:/workspace#
root@node1:/workspace# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 05:55 pts/0 00:00:00 /bin/bash
root 12 1 0 05:55 pts/0 00:00:00 ps -ef
root@node1:/workspace# exit
[node1] (local) root@192.168.0.38 ~/tensorrt-inference-server
$
root@node1:/workspace#
是因为/workspace
是dockerfile中设置的默认工作目录,而root
是该图像的默认用户。/bin/bash
命令后,您还进入了docker run
shell,因为/bin/bash
是该映像的默认入口点。您可以通过运行以下命令来验证这一点:$ docker inspect tensorrtserver_client
[
{
"Id": "sha256:90fd86dbcced04a0c585f96debc5a43b5e96bf5adfde5c7f71469d50e51ee3cd",
"RepoTags": [
"client:latest"
],
"RepoDigests": [],
"Parent": "sha256:8594a21faf37dbad5a9a8a2bd0129b26ebb68a6ba07a145824b29a6df90d108b",
"Comment": "",
"Created": "2019-06-20T05:06:55.754977279Z",
"Container": "5b6ba9901c854df63128ead1ec7d33ceab5de0d94713a59d18eda726b03b8c76",
"ContainerConfig": {
"Hostname": "5b6ba9901c85",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=//workspace/install/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"DEBIAN_FRONTEND=noninteractive",
"LD_LIBRARY_PATH=/workspace/install/lib:"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"ENV LD_LIBRARY_PATH=/workspace/install/lib:"
],
"ArgsEscaped": true,
"Image": "sha256:8594a21faf37dbad5a9a8a2bd0129b26ebb68a6ba07a145824b29a6df90d108b",
"Volumes": null,
"WorkingDir": "/workspace",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "19.03.0-beta2",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=//workspace/install/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"DEBIAN_FRONTEND=noninteractive",
"LD_LIBRARY_PATH=/workspace/install/lib:"
],
"Cmd": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "sha256:8594a21faf37dbad5a9a8a2bd0129b26ebb68a6ba07a145824b29a6df90d108b",
"Volumes": null,
"WorkingDir": "/workspace",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 2315059023,
"VirtualSize": 2315059023,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/403233de5c00747b4a081a690b387da1738e7a00254fc1df54dbd36709971637/diff:/var/lib/docker/overlay2/88e55cce134753ec862d10327241d8b3fcf17c37b367eb6c0cc4a174ad680dff/diff:/var/lib/docker/overlay2/cc4b321d2464be848bf8c2eb641761fecaf0f018b425c4bac56f83b102b4284d/diff:/var/lib/docker/overlay2/6b6a22a0a32f538f30fc10f9aa7ef7ee7473bb60866d8a68e09bce8a6ac0f507/diff:/var/lib/docker/overlay2/85eda7a5ccaab757f25815af57550c0a7b2a542c50cdfa790b42441b261864fc/diff:/var/lib/docker/overlay2/ab4724f8aa278bcb3bdf94d2cfe6c4c4a4005603e46ff61ff81c17d9c92be96c/diff:/var/lib/docker/overlay2/8532010cf9fc575e15f10f62583532a39d080244014b373cee6cc7dab0106678/diff:/var/lib/docker/overlay2/bf05834ad49520b48da6087491d024d60fb4534c5570a9260ef13828c051b179/diff:/var/lib/docker/overlay2/29c653558989a2d853d501034dcf1b58e12d5bcf5b105f84271727b33e157d65/diff:/var/lib/docker/overlay2/578aa342e497269c0f025638ee66ae8a817fc33205ac2765abbc086e74fdde94/diff:/var/lib/docker/overlay2/cbe81f7aac93e8c005537aca3c5212f916717a782ff07e4987440d4733a8c4ec/diff:/var/lib/docker/overlay2/e903955578b6b93db3149c6e4c62af229689100d21f8b8726b8615cee78c214d/diff:/var/lib/docker/overlay2/46e607b2b3826f4021af2c80e41f16868d2c97ed83ea623c103af8a96302d28b/diff:/var/lib/docker/overlay2/580aa8b144b93301e2bbe0f8bb8949e77910eeaf4bb484744a073610ab398faa/diff:/var/lib/docker/overlay2/0b2c6f5f78d999e9084c91b1565e527ebb0e89e9fc80c63528332da8cbd78c83/diff:/var/lib/docker/overlay2/7f8629cdcfc2df52b06a4087c3b97530e472de12ccc01cf9d642800a85ec0253/diff",
"MergedDir": "/var/lib/docker/overlay2/549a515d33082611583bcb0ad42b7f0d2ed9c8569ef38cecd62df2a0b12705ca/merged",
"UpperDir": "/var/lib/docker/overlay2/549a515d33082611583bcb0ad42b7f0d2ed9c8569ef38cecd62df2a0b12705ca/diff",
"WorkDir": "/var/lib/docker/overlay2/549a515d33082611583bcb0ad42b7f0d2ed9c8569ef38cecd62df2a0b12705ca/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:1ea5a27b0484f2a227275fbb913d281461d9f356134a56002574904c3cfdea04",
"sha256:24ab7de5faec98f9068e68257ce51c43cb98044a108e3f7f107e60bba3ad2ef4",
"sha256:10e46f329a252698b52d88487165156ba4a52e5b62e75e10436e4353ae6ca687",
"sha256:92d3f22d44f3a9ffaa7bbdf9d7ba902a66d39ab8d72e791b60b63a5b813ffa31",
"sha256:47abeda4e29f00f3889731dcda169734217a18d746c9582281e1868ac9ace405",
"sha256:8fc379b31a250d7b871cd58226d208b6dee1e8a354087f8e7e4c1bcc96ef534e",
"sha256:a0c43a55c96bd23d6031e0f7c47ae987253f7d4f95b78b116dd49575541a02b3",
"sha256:aa3a23d6d3ea279a468307bcb8c0c8f14075783f0280fb4a63b9095de2400783",
"sha256:525a96836c3ce61202e704d92f05c842a49e39f2e3c5f38f14ba53ea570e24e3",
"sha256:7d6c0707126d5cf34fde14b7beea34ae44c535b3a3301cdf66904c4f0e03a44d",
"sha256:d454ca1494271bc0b97298214398db2131c76489227e5aece93a7cd6ba4e5a10",
"sha256:8d7a3022550d6afc42827dd76ae76fec2f45714244fef59625b743d06d0429e9",
"sha256:f48bf567fc7abcb6fd201d4cc6e681810a8c2bf4ae86bc0ff05f808cd8d5ee02",
"sha256:3e2618d9f97998a99d605e264ac282374854e1fa18dcdc92b430794de9edc782",
"sha256:dc97ef09b5fcc5ae74457629fb8ab45dfc817c9fa9de85243045d14341d88534",
"sha256:4aa8735a33cf1223b12dbd3e3fd4af6aa9d0f14a17f4273bc7cd04f17288b544",
"sha256:db091c30373fbc4884cfe21a315df24643c4e8801ed2cb3d7984ecc6be4e181f"
]
},
"Metadata": {
"LastTagTime": "2019-06-20T05:06:55.838215092Z"
}
}
]
entrypoint
设置为null
“ Entrypoint”:空,
CMD
中提到的命令(在您的情况下为/bin/bash
)。如上述输出所示。“命令”:[
“ / bin / bash”
],
CMD
,请在运行docker run
命令时指定,如下所示:$ docker run -it --rm --net=host client /bin/sh
# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 05:48 pts/0 00:00:00 /bin/sh
root 7 1 0 05:49 pts/0 00:00:00 ps -ef
#
entrypoint
选项覆盖默认--entrypoint
。$ docker run -it --rm --net=host --entrypoint /bin/sh client
# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 1 05:50 pts/0 00:00:00 /bin/sh
root 6 1 0 05:50 pts/0 00:00:00 ps -ef
#
CMD
和ENTRYPOINT
之间的区别,请检查this。希望这会有所帮助,让我知道。
答案 2 :(得分:1)
摘自文档(docker run --help
):
-i, --interactive Keep STDIN open even if not attached
-t, --tty Allocate a pseudo-TTY
因此,“-it”本身并不存在,但却是“ -i -t”的缩写。
docker run
启动一个容器并在该容器内执行给定命令。如果提供的命令实际上将标准打开,则“ -it”选项仅指示docker将标准保持打开状态(显示提示)。
运行docker run
就像通过ssh连接到远程主机一样。身份验证之后,您会看到在远程主机上定义的提示。在docker run
之后,您会看到提示,提示是由容器内的操作系统定义的,或者是在映像构建过程中如何配置的提示(在Dockerfile中定义)。
不好意思,如果提示更改,则您的命令成功。如果没有,那么您不在容器内。
希望这会有所帮助