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

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
主站蜘蛛池模板: 舞钢市| 威信县| 嘉祥县| 桐庐县| 苗栗市| 宝山区| 炎陵县| 华阴市| 大理市| 麟游县| 巫山县| 特克斯县| 平原县| 海阳市| 岑巩县| 台前县| 肃北| 龙州县| 衡水市| 资源县| 锡林浩特市| 扶余县| 霞浦县| 德庆县| 芜湖县| 错那县| 乳山市| 晋江市| 广饶县| 天峻县| 苏尼特右旗| 晋州市| 仁怀市| 金溪县| 夏河县| 来宾市| 视频| 旌德县| 宾阳县| 商水县| 奉节县|