参考自:
http://www.jikexueyuan.com/course/859.html
http://www.jikexueyuan.com/course/876.html
镜像存放的位置 /var/lib/docker
docker images [OPTIONS] [REPOSITORY]
-a, –all=false Show all images (default hides intermediate images)
–digests=false Show digests
-f, –filter=[] Filter output based on conditions provided
–help=false Print usage
–no-trunc=false Don’t truncate output
-q, –quiet=false Only show numeric IDs
当运行docker images 可以看到:
其中 PEROSITORY就是仓库,TAG 就是标签
docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]
-f, –format= Format the output using the given go template
–help=false Print usage
–type= Return JSON for specified type, (e.g image or container)
docker rmi [OPTIONS] IMAGE [IMAGE...]
-f, –force=false Force removal of the image
–help=false Print usage
–no-prune=false Do not delete untagged parents
docker search [image]
docker pull [image]
-a, –all-tags=false
加速
使用 –registry-mirror 选项
1. 修改: /etc/default/docker
2. 添加: DOCKER_OPTIOS = “–registry-mirror=http://XXXX”
docker push
docker commit 通过容器构建
docker build 通过Dockerfile文件构建
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
-a, –author= Author (e.g., “John Hannibal Smith hannibal@a-team.com”)
-c, –change=[] Apply Dockerfile instruction to the created image
–help=false Print usage
-m, –message= Commit message
-p, –pause=true Pause container during commit
例子:
docker run -d --name test_web -p 80:80 billvsme/web nginx -g "daemon off;"
docker build [OPTIONS] PATH | URL | -
–no-cache=false Do not use cache when building the image
-q, –quiet=false Suppress the verbose output generated by
-t, –tag= Repository name (and optionally a tag) for the image
例子:
docker build -t =‘billvsme/web‘ ./
docker history [image]
注释
# Comment
指令
FROM
FROM <image>
FROM <image>:<tag>
已存在的镜像
基础镜像
必须是第一条非注释指令
MAINTAINER
MAINTAINER <name>
指定镜像第作者学习
指定当前镜像中运行的命令
RUN
RUN <command> (shell模式)
RUN echo hello
RUN ["executable", "param1", "param2"] (exec 模式)
RUN ["/bin/bash", "-c", "echo hellow"]
EXPOSE
指定容器运行端口,只是告诉docker该容器会使用这个端口,但不会自动打开端口,而是要在run 中添加端口的映射指令。
例子:
#First Dockerfile
FROM ubuntu:14.04
MAINTAINER billvsme "994171686@qq.com"
RUN apt-get update
RUN apt-get install -y nginx
EXPOSE 80
其他指令
CMD
CMD command param1 param2 (shell模式)
CMD [‘executable‘, "param1", "param2"] (exec模式)
CMD [‘param1‘, ‘param2‘] (作为ENTERYPOINT指令的默认参数)
RUN 指令的命令是在容器构建时候运行的,CMD命令是在容器运行时运行的,并且如果docker run 指定cmd命令,CMD命令会被覆盖
ENTERYPOINT
ENTERYPOINT command param1 param2(shell模式)
ENTERYPOINT [‘executable‘, "param1", "param2"] (exec模式)
跟CMD的区别就是,ENTERYPOINT 不会被覆盖,如果想覆盖,可以使用 docker run --entrypoint 覆盖
COPY
COPY <src> ... <desc>
COPY ["<src>"..."<dest>"] (适用于文件路径中有空格的情况)
ADD
ADD 于COPY基本相同,只是ADD提供了类似tar的解压功能,ADD src 可以是url
VOLUME
VOLUME ["/data"] 向容器添加卷
WORKDIR
WORKDIR /path/to/workdir
在容器内部设置工作目录,后面CMD、ENTERYPOINT 都会在这个目录下执行
ENV
ENV <key><value>
ENV <key>=<value>...
设置环境变量
USER
USER uid
USER uid:gid
USER uid:group
USER nginx
以nginx 身份运行
默认是root
ONBUILD
ONBUILD [INSTRUCTION]
镜像触发器
当一个镜像被其他镜像作为基础镜像时执行,这个触发器会被执行
当子镜像在构建时会插入触发器当指令
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/billvsme/article/details/49031951