通常我們在官方下載的鏡像不能夠切合的在我們生產環境中使用,比如缺包,和我們環境中所需要的環境軟件版本不一致等,所以我們要自己製作鏡像
製作鏡像又兩種方法:
-
啓動docker容器後,把容器打包成鏡像
docker commit 容器名字 鏡像名字
docker commit httpd-1 httpd-1-commit - Docker file 通過Docker file 可以通過自己的對鏡像的的修改,並生成一個新的鏡像.
下面我們來做一個Dockerfile
[root@docker Dockerfile]# cat Dockerfile
FROM httpd-1-commit
RUN touch /root/test
[root@docker Dockerfile]# docker build -t httpd-1-commit-with-touch .
Sending build context to Docker daemon 2.048 kB
Step 1/2 : FROM httpd-1-commit
---> d5e604e49f5c
Step 2/2 : RUN touch /root/test
---> Using cache
---> f8f075f7140d
Successfully built f8f075f7140d
使用方法:
docker build -t {image name } {Dockerfile path}
注意dockerfile 所在目錄一定要在Dockerfile 目錄下,否則會報 錯誤;
[root@docker home]# docker build -t with-touch-1 .
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/Dockerfile: no such file or directory
若不想使用image的緩存,則在加上--no-cache 的參數
docker build --no-cache -t {image name } {Dockerfile path}
下一篇 docker image 私有倉庫製作
https://blog.51cto.com/shyln/2130308