Dockerfile: create an image Template

Source: Internet
Author: User
Tags pagekit

Dockerfile: create an image Template

Dockerfile is a configuration file in text format. You can use Dockfile to quickly create a custom image. Dockerfile is composed of a line of command statements, and supports comment lines starting.

# Generally, Dockerfile is divided into four parts: basic image information, maintainer information, image operation instructions, and container startup commands.
The template is as follows:

# This dockerfile uses the Ubuntu image
# Specify the basic Image Based on. You can use multiple FROM commands.
# FROM <image> or FROM <image >:< tag>

# MAINTAINER specifies the MAINTAINER Information
# MAINTAINER UserName <cheng@xxxx.com>

# ENV specifies an environment variable, which will be used by subsequent RUN commands and maintained during container runtime.
# ENV <key> <value>

# RUN image operation commands
# The format is RUN <command> or RUN ["executable", "param1", "param2"]. The former runs the command in the shell terminal, that is,/bin/sh-c; the latter can be executed using exec.

# Copy <src> (the relative path, file, or directory of the Docker directory) of the local host as <dest> in the container. If the target path does not exist, it is automatically created. COPY is recommended when the local directory is the source directory.
# COPY <src> <dest>

# ENTRYPOINT, in two formats
#1. ENTRYPOINT ["executable", "param1", "param2"]
#2. ENTRYPOINT command param1 param2 (executed in shell)
# Each Dockerfile can have only one ENTRYPOINT. If multiple entrypoints are specified, only the last one takes effect. Configure the commands executed after the container is started and cannot be overwritten by the parameters provided by docker run>.

# EXPOSE indicates the port number exposed by the Docker server container for the interconnected system.
# EXPOSE <port> [<port>...]

# Copy the specified <src> to <dest> in the container. <src> enables a relative path (file or directory) in the directory where Dockerfile is located, or a URL; it can also be a tar file (automatically decompress it as a directory ).
# ADD <src> <dest>

# VOLUME creates a mount point that can be mounted from a local host or other containers. It is generally used to store databases and data to be maintained.
# VOLUME ["/data"]

# USER specifies the USER name or UID when running the container, and the specified USER will be used for subsequent RUN. Gosu must be used to temporarily obtain administrator permissions. sudo is not recommended. If this parameter is not specified, the container runs as root by default.
# USER daemon

# WORKDIR is the working directory configured for subsequent RUN \ CMD \ ENTRYPOINT commands. You can use multiple WORKDIR commands. If the parameters of subsequent commands are relative paths, they are based on the paths specified by the previous commands.
# WORKDIR/path/to/workdir
# Example:
WORKDIR/
WORKDIR B
WORKDIR c
RUN pwd
# The final path is/a/B/c.

# The operation commands executed by ONBUILD when the created image is configured as the basic image of another newly created image. For images using the ONBUILD command, we recommend that you specify it in the tag, for example, nginx: 1.9.11-onbuild.
# ONBUILD [INSTRUCTION]

# The CMD container executes commands at startup. Three formats are supported.
# 1.CMD ["executable", "param1", "param2"]
# 2.CMD command param1 param2 is executed in/bin/sh and provided to applications requiring interaction
# 3.CMD ["param1", "param2"] default parameters provided to ENTRYPOINT
# If multiple commands are specified, only the last one will be executed. If you specify the running command when starting the container, the command specified by CMD will be overwritten.

For example:
Vi Dockerfile
# This dockerfile uses the pagekit
FROM ubuntu: trusty
MAINTAINER UserName <cheng@ule.com>
RUN apt-get update &&\
Apt-get-y install &&\
Nginx \
Unzip \
Wget \
Ca-certificates \
Php5 php5-fpm php5-cli php5-json php5-mysql
ENV PAGEKIT_VERSION 1.0.2
RUN mkdir pagekit
WORKDIR/pagekit
VOLUME ["/pagekit/storage", "/pagekit/app/cache"]
RUN wget upload-O/pagekit/pagekit.zip &&\
Unzip/pagekit/pagekit.zip & rm/pagekit/pagekit.zip
ADD nginx. conf/etc/nginx. conf
RUN chown-R wwwdata:/pagekit &&\
Apt-get autoremove wget unzip-y &&\
Apt-get autoclean-y &&\
Apt-get clean-y &&\
Rm-rf/varf/lib/apt/list/tmp // var/tmp /*
CMD ["sh", "-c", "service php5-fpm start & nginx"]

For more Docker tutorials, see the following:

Docker installation application (CentOS 6.5_x64) https://www.bkjia.com/Linux/2014-07/104595.htm
Configuration on Ubuntu 16.04 server using Docker https://www.bkjia.com/Linux/2017-06/145176.htm
Install Docker https://www.bkjia.com/Linux/2015-07/120444.htm in Ubuntu 15.04
Docker installation instance https://www.bkjia.com/Linux/2017-04/142666.htm
Docker create basic image https://www.bkjia.com/Linux/2017-05/144112.htm
How to install Docker and basic usage https://www.bkjia.com/Linux/2015-09/122885.htm on Ubuntu 15.04
Docker Use note https://www.bkjia.com/Linux/2016-12/138490.htm on Ubuntu 16.04
Use Docker to start https://www.bkjia.com/Linux/2017-04/142649.htm of frequently used applications in minutes
Ubuntu 16.04 Docker modify configuration file does not take effect solution https://www.bkjia.com/Linux/2017-05/143862.htm

Docker details: click here
Docker: click here

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151349.htm

Related Article

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.