阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

理解dockerfile是如何工作的?

207次阅读
没有评论

共计 2344 个字符,预计需要花费 6 分钟才能阅读完成。

理解 dockerfile 是如何工作的?

1. 下面是一个最简单的 dockerfile:

FROM baserepo

RUN do something

2. 这个 dockerfile build 完等价于下面的命令:

Step 0 :
sudo docker pull baserepo:latest
sudo docker run –name baserepo_bash01 -i -t baserepo:latest /bin/bash
sudo docker ps -a
b779269d5001

sudo docker commit b779269d5001 imagename01

Step 1:
sudo docker run –name baserepo_bash02 -i -t imagename01 /bin/bash
sudo docker ps -a
b779269d5001
b779269d5002

sudo docker exec -d baserepo_bash02 do something
sudo docker commit b779269d5002 imagename02

sudo docker run –name baserepo_bash -i -t imagename02 /bin/bash
sudo docker ps -a
b779269d5001
b779269d5002
b779269d5003

sudo docker stop b779269d5002
sudo docker rm b779269d5002
sudo docker rmi imagename01

sudo docker ps -a
b779269d5001
b779269d5003

sudo docker images
baserepo:latest
imagename02

3. 如果看不懂这做的事情,那参照下面的例子理解下

Take the following Dockerfile:
FROM base
RUN echo ‘foo’ > /tmp/foo.txt
RUN echo ‘bar’ >> /tmp/foo.txt

and build it:
$ docker build –force-rm -t so-26220957 .
Sending build context to Docker daemon 3.584 kB
Sending build context to Docker daemon
Step 0 : FROM base
 —> b750fe79269d
Step 1 : RUN echo ‘foo’ > /tmp/foo.txt
 —> Running in d37d756f6e55
 —> de1d48805de2
Removing intermediate container d37d756f6e55
Step 2 : RUN echo ‘bar’ >> /tmp/foo.txt
 —> Running in a180fdacd268
 —> 40fd00ee38e1
Removing intermediate container a180fdacd268
Successfully built 40fd00ee38e1

You can now start a new container from b750fe79269d, de1d48805de2 and 40fd00ee38e1:
$ docker run –rm b750fe79269d cat /tmp/foo.txt
cat: /tmp/foo.txt: No such file or directory

$ docker run –rm de1d48805de2 cat /tmp/foo.txt
foo

$ docker run –rm 40fd00ee38e1 cat /tmp/foo.txt
foo
bar

of course you might want to start a shell to explore the filesystem and try out commands:
$ docker run –rm -it de1d48805de2 bash -il
root@ecd3ab97cad4:/# ls -l /tmp
total 4
-rw-r–r– 1 root root 4 Oct  6 18:34 foo.txt
root@ecd3ab97cad4:/# cat /tmp/foo.txt
foo
root@ecd3ab97cad4:/#
来源于:http://stackoverflow.com/questions/26220957/how-can-i-inspect-the-file-system-of-a-failed-docker-build

总结下:dockerfile 做的事情其实就是拉镜像,镜像启容器,容器转镜像,镜像再启容器,容器再转镜像,删除中间镜像和容器,大概就是这样的。

Docker 安装应用 (CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm

在 Docker 中使用 MySQL http://www.linuxidc.com/Linux/2014-01/95354.htm

在 Ubuntu Trusty 14.04 (LTS) (64-bit) 安装 Docker http://www.linuxidc.com/Linux/2014-10/108184.htm

Docker 安装应用 (CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm

Ubuntu 14.04 安装 Docker  http://www.linuxidc.com/linux/2014-08/105656.htm

阿里云 CentOS 6.5 模板上安装 Docker http://www.linuxidc.com/Linux/2014-11/109107.htm

Docker 的详细介绍 :请点这里
Docker 的下载地址 :请点这里

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计2344字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中