Docker 入门
三个基本要素:
- Docker Containers 负责应用程序的运行
- Docker Images 一个只读模板,用来运行Docker容器
- DockerFile 文件指令集,用来说明如何自动创建Docker镜像
Docker 命令
- docker info
- docker pull [image_name]
- docker run [image_name] /bin/echo aaa ...
- sample_job=$(docker run -d busybox /bin/sh -c "while true; do echo Docker; sleep 1; done")
- docker logs [$sample_job]
- docker help
- docker stop [$sample_job]
- docker restart [$sample_job]
- docker rm [$sample_job]
- docker commit [$sample_job] [job1]
- docker images
- docker search [image-name]
- docker history [image_name]
- docker push [image_name]
Docker File 指令
- FORM [image_name]
- MAINTAINER [author_name]
- RUN [command]
- ADD [src] [destination]复制文件指令
- CMD [command]
- EXPOSE [port] 指定容器在运行时监听的端口
- ENTRYPPOINT [command] [param1] [param2]
- WORKDIR [/path/to]
- ENV [key] [value]
- USER [uid]
- VOLUME [“/data”]
Docker registry工作机制
- registry三个主要模块 Docker Client, Index, Registry
Docker 指令
- Docker daemon
- docker build image_name path
- docker attach container 与运行中的容器交互
- docker diff container 列出容器内发生变化的文件和目录
- docker import http://example 从远程导入文件到container
- docker import - image_app 从本地导入文件或者目录
- docker export container_id > image.tar 将容器的系统文件打包成tar文件
- docker cp container:path hostpath 从容器内复制文件到指定的本地路径上
- docker login 登录registry
- docker inspect container/image 收集容器和镜像的底层信息
- docker kill container
- docker rmi image
- docker wait container
- docker load app.tar
- docker save image > app.tar