Use Dockerfile to build an image

Source: Internet
Author: User

Use Dockerfile to build an image
Create a directory and initialize Dockerfile .~ Mkdir static_web? ~ Cd static_web? Static_web touch Dockerfile? Static_web vim Dockerfile we create a directory named static_web to save the Dockerfile. This directory is our build environment, and Docker calls this environment the build context. Docker uploads the files and directories of the build context and context to the Docker daemon when building the image, and the Docker daemon can directly access any code stored in the image.
Dockerfile file: # Version 0.0.1FROM ubuntu: 14.04 MAINTAINER wangxigang "wangxigang2014@gmail.com" RUN apt-get updateRUN apt-get install-y nginxRUN echo 'Hi, I am in your container '\>/user/share/nginx/html/index.html ESPOSE 80
Each Command in Dockerfile creates a new image layer and submits the image. Docker generally runs the commands in Dockerfile as follows:

  • Docker runs a container from the basic image
  • Execute a command to modify the container
  • No new image layer is submitted for the docker commit-like operation.
  • Docker runs a new container Based on the just-submitted Image
  • Execute the next command in dockerfile until all the commands are executed.

When you run the Docker build command, all commands in the Dockerfile will be executed and submitted. A new image will be returned after the command is successfully completed.
? Static_web docker build-t = "wangxigang/static_web: v1 ". sending build context to Docker daemon 2.048 kBSending build context to Docker daemonStep 0: FROM ubuntu: 14.04 ---> d0955f21bf24Step 1: MAINTAINER wangxigang "wangxigang2014@gmail.com" ---> Using cache ---> 483dea6225f5Step 2: RUN apt-get update ---> Using cache ---> 04193630d05eStep 3: RUN apt-get install-y nginx ---> Using cache ---> 789653de1b1fStep 4: RUN echo 'Hi, I am in your container '---> Running in 7c6254e520aaHi, I am in your container ---> using intermediate container 7c6254e520aaStep 5: ESPOSE ---> using built f24d8b751f89
Check whether the image is successfully created:
In dockerimages, you will see the image with the id of none: # Delete the image with the id of none, that is, the image with the id of none $ docker rmi $ (docker images-q -- filter "dangling = true ")


Https://docs.docker.com for more information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.