- Learn OpenShift
- Denis Zuev Artemii Kropachev Aleksey Usov
- 294字
- 2021-08-13 16:03:48
Using Dockerfile build
Usually, those who use Docker containers expect to have a high-level of automation, and the docker commit command is difficult to automate. Luckily, Docker can build images automatically by reading instructions from a special file usually called a Dockerfile. A Dockerfile is a text document that contains all the commands a user can call on the command line to assemble an image. Using docker build, users can create an automated build that executes several command-line instructions in succession. On CentOS 7, you can learn a lot more using the Dockerfile built-in documentation page man Dockerfile.
A Dockerfile has a number of instructions that help Docker to build an image according to your requirements. Here is a Dockerfile example, which allows us to achieve the same result as in the previous section:
$ cat Dockerfile
FROM httpd
RUN echo "This is a custom image" > /usr/local/apache2/htdocs/index.html
Once this Dockerfile is created, we can build a custom image using the docker build command:
$ docker build -t custom_image2 .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM httpd
---> 01154c38b473
Step 2 : RUN echo "This is a custom image" > /usr/local/apache2/htdocs/index.html
---> Using cache
---> 6b9be8efcb3a
Successfully built 6b9be8efcb3a
docker build -t custom_image2 .
or
docker build -t custom_image2 ./
or
docker build -t custom_image2 $(pwd)
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
custom_image2 latest 6b9be8efcb3a 2 minutes ago 177.4 MB
custom_image latest ffd3a523f984 19 minutes ago 177.4 MB
docker.io/httpd latest 01154c38b473 2 weeks ago 177.4 MB
- Windows Vista基礎與應用精品教程
- 鴻蒙生態:開啟萬物互聯的智慧新時代
- Ansible權威指南
- Mastering Distributed Tracing
- Linux就該這么學
- Learning Bootstrap
- Linux內核設計的藝術:圖解Linux操作系統架構設計與實現原理
- VMware Horizon View Essentials
- Python UNIX和Linux系統管理指南
- 寫給架構師的Linux實踐:設計并實現基于Linux的IT解決方案
- Linux網絡配置與安全管理
- Windows 10從新手到高手
- Heroku Cloud Application Development
- 從零開始學安裝與重裝系統
- Linux軟件管理平臺設計與實現