官术网_书友最值得收藏!

  • 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
Please note that the . at the end of the first line is important as it specifies the working directory. Alternatively, you can use ./ or even $(pwd). So the full commands are going to be: 

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
主站蜘蛛池模板: 天全县| 九龙坡区| 松桃| 上犹县| 双城市| 威海市| 临颍县| 尼勒克县| 新乐市| 博罗县| 遂平县| 宜兴市| 绥阳县| 个旧市| 米易县| 南和县| 镇赉县| 方正县| 宜春市| 平南县| 商丘市| 武汉市| 武穴市| 柳州市| 凤城市| 安远县| 南溪县| 江山市| 朝阳县| 军事| 东山县| 元阳县| 彝良县| 张家港市| 唐海县| 耒阳市| 资阳市| 保亭| 东丽区| 新巴尔虎左旗| 海兴县|