docker - 容器commit为镜像,再run成container, 端口映射丢失 该如何理解.
ringa_lee
ringa_lee 2017-04-24 09:09:34
0
3
847

问个问题啊, 我run 了一个container hello,通过-p参数 映射主机端口 和 容器端口.

sudo docker run -d --name hello -p 8080:8080 -m 268435456 ubuntu:14.04 bin/bash -c "while true;do echo hello $(date); sleep 2; done"

然后通过 commit 命令生成新的镜像 sudo docker commit hello hello-image .
在然后, 基于该镜像,使用docker run -d hello-image 重新运行一个新的容器(这个时候并没有指定-p参数).
新生成的容器 是没有 端口映射的,而且也没有之前容器设置的-m参数信息.

我的问题是: 如何理解新生成的容器没有映射端口和 内存限制这两项信息? 什么参数是属于容器的,什么参数是属于镜像的呢?

ringa_lee
ringa_lee

ringa_lee

reply all(3)
阿神

When the container is committed into a mirror, only the static files will be retained, because the container itself is also stopped at this time

巴扎黑

You need to reserve the port, or use the dockerfile to open the port, and use the -P command when creating the container.
Or still run similar to the way you specified the port above. Otherwise, the port will not be opened, and everything related to the host must be dynamically specified when the container needs to be created.
sudo docker run -d --name hello -p 8080:8080 -m 268435456 ubuntu:14.04 bin/bash -c "while true;do echo hello $(date); sleep 2; done"

左手右手慢动作

Port mapping belongs to the container and will not exist in the image. It must be specified every time it runs.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!