Docker – 容器在构build后被移除

我用下面的Dockerfile构build我的项目:

 FROM ubuntu:14.04 #"updating package repos.." RUN apt-get update #"installing required packages.." RUN apt-get -y install python2.7-dev build-essential python-pip run apt-get -y install libjpeg-dev libpng3 libpng12-dev run apt-get -y install nodejs npm nodejs-legacy run npm install -g peer run apt-get -y install supervisor #"creating sites folder under /opt" run mkdir /opt/sites #"copying project into /opt/sites" add project-latest /opt/sites/project-latest #"copying supervisor conf into /etc/supervisor/conf.d" add etc/project.conf /etc/supervisor/conf.d/ #"installing virtualenv" run pip install virtualenv #"change working dir to /opt/sites/project-latest" workdir /opt/sites/project-latest #"create vritualenv folder named 'env' " run virtualenv env #"activating environment" run . env/bin/activate #"installing packages into env from requirements.txt" run pip install -r requirements.txt #"syncing DB" run python manage.py syncdb #"migrating DB" run python manage.py migrate #"update and restart supervisorctl" run service supervisor start cmd supervisorctl reread cmd supervisorctl update cmd supervisorctl restart all #"expose 8000 and 9000 ports" expose 8000 expose 9000 

这是构build过程的最终输出:

 Successfully built 29dbd8e8bb0a Removing intermediate container 8a20545921e0 Removing intermediate container 0da63841f6ad Removing intermediate container fab164fe93c2 Removing intermediate container 77b61eceef36 Removing intermediate container 87a24b079f47 Removing intermediate container cb2520749e30 Removing intermediate container 9e9c54376433 Removing intermediate container 130f6eaeed6a Removing intermediate container 56f9d93a1e75 Removing intermediate container 599b10008caa Removing intermediate container eab7598a5e95 Removing intermediate container c31b58fcc405 Removing intermediate container 8b4a55fbb345 Removing intermediate container 13b35d86044e Removing intermediate container 0ab10eef8f5e Removing intermediate container ebf42d9493f1 Removing intermediate container 70c772c4aa73 Removing intermediate container fe5039bfbe15 Removing intermediate container 8f9a93cd5438 Removing intermediate container 2d673cf029f8 Removing intermediate container ab8485d09ee7 Removing intermediate container 0fdfa200ac27 Removing intermediate container d2d02358e25d 

如果我创build一个容器来在我的内置图像中运行bash ,我会看到一些构build步骤被遗忘。 即没有我的requirements.txt文件的虚拟环境。

我不知道如何从我的主机打开我的正在运行的django application 。 没有任何端口或IP信息。

删除中间图像是正常的。 如果你想保留它们,你必须添加--rm=false到你的构build命令。

Dockerfile有几个问题。 对于初学者来说,只有最后一个CMD才会生效(这里是文档 )。

另外,这条线看起来很可疑:

 run . env/bin/activate 

我想这是为了设置一些环境variables,但我不认为这是docker工程的方式。 我认为,要么你必须使用ENV命令,否则你将不得不一起运行这个和下面的命令:

 run . env/bin/activate; pip install -r requirements.txt; python manage.py syncdb; python manage.py migrate 

关于端口,你用-p-P选项运行映像吗?