Dockerfile is a text file that contains instructions. Each instruction builds a layer, so the content of each instruction describes how the layer should be built. Dockerfile supports the Shell-like command line-ending method of adding "\" at the end of the line and the comment format of "#" at the beginning of the line. Note when using Dockerfile to build a Docker image: (1) Try to select a basic system image that meets your needs but is smaller; (2) Clean up temporary files such as compiled files and installation package cache; (3) When installing each software, specify the exact version number and avoid introducing unnecessary dependencies; (4). Add a .dockerignore file or use a clean working directory. Common instructions for Dockerfile:(1).FROM: used to specify the base image to be built, which is usually the first instruction in the Dockerfile; (2) LABEL: used to add labels to help organize images, record license information, assist in automated builds, etc. Labels are key-value pairs stored as strings; (3). RUN: used to execute commands in the image, which will create a new image layer. Each RUN instruction creates a new image layer, and always combines apt-get update and apt-get install into one RUN; The RUN instruction has two formats:A. Shell format: RUN <command>, just like the command entered directly in the command line; B.exec format: RUN ["executable file", "parameter 1", "parameter 2"]; (4) COPY: supports simple copying of local files into the container. The COPY instruction is usually used to assign application code to the image. (5).EXPOSE: used to record the network ports used by the application; (6).ENTRYPOINT: used to specify the program that runs by default after the image is started in container mode; (7).ENV: Updates the PATH environment variable for programs installed in the container. The following Dockerfile is used to compile and execute directly in the container https://github.com/fengbingchun/Messy_Test: FROM ubuntu:16.04 LABEL maintainer="FengBingchun [email protected]" \ version="1.0" \ description="dockerfile test" RUN dep_items='git cmake g++-5' \ && apt-get update \ && apt-get install -y $dep_items \ && ln -s /usr/bin/g++-5 /usr/bin/g++ \ && rm -rf /var/lib/apt/lists/* Build the image. After executing the following command, an image named fengbingchun/ubuntu:16.04 will be successfully generated: docker build -t fengbingchun/ubuntu:16.04 . By mounting the host directory, create a new container test and execute the following command: docker run -it -P --name test --mount type=bind,source=e:\GitCode\docker,target=/home/fengbingchun fengbingchun/ubuntu:16.04 /bin/bash Then, in the container, cd to the /home/fengbingchun directory, clone Messy_Test and execute the following command: git clone https://github.com/fengbingchun/Messy_Test Then cd to the cd Messy_Test/prj/linux_cmake_CppBaseTest directory and execute the following commands in sequence ./build.sh ./build/CppBaseTest The execution result is shown in the figure below, indicating that the image built by Dockerfile can compile and execute Messy_Test normally: Save the image fengbingchun/ubuntu:16.04 to a tarball and execute the following command: docker save -o ubuntu_16.04.tar fengbingchun/ubuntu:16.04 Copy ubuntu_16.04.tar to the Ubuntu system, load an image from the tarball, and execute the following command: docker load -i ubuntu_16.04.tar Then perform similar operations on Windows, compile and execute Messy_Test in the newly created container test, and execute the following commands in sequence: docker run -it -P --name test --mount type=bind,source=/home/xxxx/Disk/GitHub/docker,target=/home/fengbingchun fengbingchun/ubuntu:16.04 /bin/bash cd /home/fengbingchun/ git clone https://github.com/fengbingchun/Messy_Test cd Messy_Test/prj/linux_cmake_CppBaseTest/ ./build.sh ./build/CppBaseTest The execution result is shown in the figure below: It shows that after the image generated on Windows is packaged, it can be used normally after loading on Ubuntu. This concludes this article about the steps to build a Docker image using Dockerfile. For more information about building a Docker image using Dockerfile, please search for previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Creating a Secondary Menu Using JavaScript
>>: Simple web page code used in NetEase blog
Network security is a very important topic, and t...
Preface This article will explain how Vue compone...
Last week, the teacher gave me a small homework, ...
The MERGE storage engine treats a group of MyISAM...
In the fifth issue of Web Skills, a technical sol...
Table of contents origin status quo Cancel reques...
1For example: To split the fields shown in Figure...
The image can be saved on hub.docker.com, but the...
MySQL add, delete, modify and query statements 1....
In an unordered list ul>li, the symbol of an u...
The display without the effect picture is just em...
Using provide+inject combination in Vue First you...
There are some differences between filter and bac...
When developing a Vue project, you often need to ...
Find the problem Recently, I encountered a proble...