Docker - 构建后删除容器

时间:2014-06-16 17:29:51

标签: docker

我使用以下Dockerfile构建我的项目:

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

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

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

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

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

1 个答案:

答案 0 :(得分:14)

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

您的Dockerfile存在一些问题。对于初学者,只有最后CMD生效(此处为the docs)。

此外,这一行看起来很可疑:

run . env/bin/activate

我想这意味着设置一些环境变量,但我不认为这是docker的工作方式。我认为您必须使用ENV命令,或者您必须同时运行此命令和以下命令:

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

关于端口,您是使用-p还是-P选项运行图片?