可以使用Dockerfile自定义镜像。
Dockerfile分为四个部分:基础镜像信息,维护者信息,镜像操作指令和容器启动时执行指令。
# This dockerfile uses the ubuntu image
# VERSION 2 - EDITION 1
# Author: docker_user
# Command format: Instruction [arguments / command] ..
# Base image to use, this must be set as the first line
FROM ubuntu
# Maintainer: docker_user <docker_user at email.com> (@docker_user)
MAINTAINER docker_user docker_user@email.com
# Commands to update the image
RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list
RUN apt-get update && apt-get install -y nginx
RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf
# Commands when creating a new container
CMD /usr/sbin/nginx
# 标注的信息为注释; FROM 标注的为该镜像维护者信息; RUN标注的为镜像操作指令; CMD标注的为容器运行时的操作指令。
指令说明
FROM
格式:FROM 或 FROM :
第一条指令必须为FROM指令,如果在一个Dockerfile中创建多个镜像时,可以使用多个FROM指令。
MAINTAINER
格式:MAINTAINER name@email.com
指定维护者信息。
RUN
格式:RUN 或 RUN [“executable”, “param1”, “param2”]
CMD
格式:CMD [“executable”,”param1”,”param2”] 或 CMD command param1 param2 或 CMD [“param1”,”param2”]
指定容器启动时执行的命令,每个Dockerfile只能有一条CMD命令。如果用户在启动容器时附加了运行命令,将会覆盖掉CMD指定的命令。
EXPOSE
格式:EXPOSE […]
指定Docker容器开放的端口号。
ENV
格式:ENV
指定环境变量。
ADD
格式:ADD
复制指定的到容器中的。可以为相对路径,URL或者tar文件均可。
COPY
格式:COPY
复制本地主机的到容器中的。
ENTRYPOINT
格式:ENTRYPOINT [“executable”, “param1”, “param2”] 或 ENTRYPOINT command param1 param2
同CMD命令,但不会被docker run提供的参数覆盖。
VOLUME
格式:VOLUME [“/data”]
创建一个可以从本地主机或其他容器挂载的挂载点,一般用来存放数据库和需要保持的数据等。
创建镜像
使用命令 “docker build [选项] 路径”创建镜像。例如:
$ sudo docker build -t myrepo/myapp /tmp/test1/
你打算打赏多少钱呢?
(微信扫一扫)