Docker Study Notes (2)

Source: Internet
Author: User
In the docker Study Notes (1), we mentioned using the commit command to submit a new image. Next we will use the Dockerfile file to generate an image and use the Dockerfile for convenient transplantation. I. Several Common commands in Dockerfile: (1) FROM: FROMimage or FROMimage: tag (2) MAINTAINER

In the docker Study Notes (1), we mentioned using the commit command to submit a new image. Next we will use the Dockerfile file to generate an image and use the Dockerfile for convenient transplantation. 1. Several Common commands in Dockerfile: (1) FROM: FROM image or FROM image: tag (2) MAINTAINER

In the docker Study Notes (1), we mentioned using the commit command to submit a new image. Next we will use the Dockerfile file to generate an image and use the Dockerfile for convenient transplantation.


I. Several Common commands in Dockerfile:
(1) FROM

Format:

FROM  
Or
 FROM  :
 

(2) MAINTAINER

Format:

MAINTAINER  
 

Description: sets the creator of the generated image.


(3) RUN

Format:

Using shell

RUN  
Or in the exec format.
RUN ["executable",  "param1",  "param2"] 

Note: The RUN Command runs the command on a new layer on the current Image and submits the result. These results will be used in the next step of Dockerfile.


(4) CMD

Format:

CMD ["executable","param1","param2"]  
Or
CMD ["param1","param2"] 
Or
CMD command param1 param2

Note: The CMD command executes the service when the container is started, for example, a command, a service, or a script.

Note: A Dockerfile can only have one CMD command. If there are multiple command lines, only the last one is valid.


(5) ADD

Format:

ADD  
 
    .... 
  
 

Note:

If you want to ADD a local file, the local file must be in the docker build , The specified Directory, such as ADD files/root/hadoop_files: lchown/var/lib/docker/aufs/mnt .......................... not a directory and other error messages)

If you want to ADD a remote file, the remote file must be in the docker build , The specified Directory, such as: ADD https://archive.apache.org/dist/hadoop/common/hadoop-1.0.4/hadoop-1.0.4-bin.tar.gz/root/


(6) VOLUME

Format:

VOLUME  ["/data"]
Note: you can mount local folders or other container folders to the container.


Ii. Example

The following Dockerfile creates an image based on ubuntu: precise.

Run the docker build-t ubuntu: base. Command.

#Authro:wgc#Data:2014-10-24#Introduction:Build basic developmentFrom ubuntu:precise# Set correct source listRUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.listRUN echo "deb http://archive.ubuntu.com/ubuntu precise-updates main universe" >> /etc/apt/sources.list# Install a few other useful packages plus Open Jdk 7RUN apt-get update && apt-get upgrade -y && apt-get install -y openjdk-7-jdk wget vim sudo openssh-server # Add hadoop_filesADD files /root/hadoop_files/# Set JAVA_HOMEENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64RUN echo export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 >> /root/.bashrc# Download hadoopADD https://archive.apache.org/dist/hadoop/common/hadoop-1.0.4/hadoop-1.0.4-bin.tar.gz /root/


Refer:

(1)docs.doc ker.com/reference/builder/

(2) http://blog.csdn.net/wsscy2004/article/details/25878223

(3) tonyunc.com/tag/blog/

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.