Usage: docker [OPTIONS] COMMAND
用法:Docker[选项]命令
A self-sufficient runtime for containers
自动运行中的容器
Options: 选项:
--config string Location of client config files (default "/root/.docker")
--配置串 客户端配置文件位置(默认"/root/.docker")
-D, --debug Enable debug mode
-D, --debug 启用调试模式
-H, --host list Daemon socket(s) to connect to
-H, --host list 连接的主机列表守护程序套接字
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
-I, --log-level string 设置日志级别("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tsl 使用TLS;由-tlsverity隐含
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
-- tlscacert string 信任证书仅由该CA签名(默认为"/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlscert string 到tls证书文件的路径(默认为"/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlskey string 到tls密钥文件的路径(默认为 "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
--tslverify 使用tls并验证远程
-v, --version Print version information and quit
-v, --version 打印版本信息并退出
Management Commands: 管理命令
builder Manage builds 管理生成
config Manage Docker configs 管理Docker配置
container Manage containers 管理容器
engine Manage the docker engine 管理Docker 引擎
image Manage images 管理镜像
network Manage networks 管理网络
node Manage Swarm nodes 管理群节点
plugin Manage plugins 管理插件
secret Manage Docker secrets 管理Docker密钥
service Manage services 管理服务
stack Manage Docker stacks 管理Docker 堆栈
swarm Manage Swarm 管理群组
system Manage Docker Docker系统管理员
trust Manage trust on Docker images 管理对Docker镜像信任
volume Manage volumes 管理卷
Commands: 命令
attach Attach local standard input, output, and error streams to a running container
attach 将本地标准输入输出和错误流附加到正在运行的容器
build Build an image from a Dockerfile
build 从Dockerfile构建镜像
commit Create a new image from a container's changes
commit 根据容器的更改创建新镜像
cp Copy files/folders between a container and the local filesystem
cp 在容器和本地文件系统之间复制文件/文件夹
create Create a new container
create 创建新容器
diff Inspect changes to files or directories on a container's filesystem
diff 检查对容器文件系统上文件或目录的更改
events Get real time events from the server
events 从服务器获取实时事件
exec Run a command in a running container
exec 在正在运行的容器中运行命令
export Export a container's filesystem as a tar archive
export 将容器的文件系统导出为tar存档
history Show the history of an image
history 显示镜像的历史
images List images
images 镜像列表
import Import the contents from a tarball to create a filesystem image
import 从tarball导入内容以创建文件系统镜像
info Display system-wide information
info 显示系统范围内的信息
inspect Return low-level information on Docker objects
inspect 返回Docker对象的下级信息
kill Kill one or more running containers
kill 杀死一个或多个正在运行的容器
load Load an image from a tar archive or STDIN
load 加载从tar存档或stdin加载镜像
login Log in to a Docker registry
login 登录到Docker注册表
logout Log out from a Docker registry
logout 从Docker注册表注销
logs Fetch the logs of a container
logs 获取容器的日志
pause Pause all processes within one or more containers
pause 暂停一个或多个容器中的所有进程
port List port mappings or a specific mapping for the container
port 端口映射或容器的特定映射列表
ps List containers
ps 容器列表
pull Pull an image or a repository from a registry
pull 从注册表中拉取镜像或存储库
push Push an image or a repository to a registry
push 将镜像或存储库推送到注册表
rename Rename a container
rename 重命名容器
restart Restart one or more containers
restart 重启一个或多个容器
rm Remove one or more containers
rm 删除一个或多个容器
rmi Remove one or more images
rmi 删除一个或多个镜像
run Run a command in a new container
run 在新容器中运行命令
save Save one or more images to a tar archive (streamed to STDOUT by default)
save 保存一个或多个镜像到tar存档(默认情况下流到STDOUT)
search Search the Docker Hub for images
search 在Docker Hub中搜索镜像
start Start one or more stopped containers
start 启动一个或多个容器
stats Display a live stream of container(s) resource usage statistics
stats 显示容器资源使用的实时流
stop Stop one or more running containers
stop 停止一个或多个容器
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
tag 创建引用源镜像的目标镜像标记
top Display the running processes of a container
top 显示容器的运行进程
unpause Unpause all processes within one or more containers
unpause 取消暂停一个或多个容器中的所有进程
update Update configuration of one or more containers
update 更新一个或多个容器的配置
version Show the Docker version information
version 显示Docker的版本信息
wait Block until one or more containers stop, then print their exit codes
wait 等待阻止直到一个或多个容器停止,然后打印其退出代码
Run 'docker COMMAND --help' for more information on a command.
运程'docker COMMAND --help'获取关于命令的更多信息
正文
镜像:Docker 镜像是用于创建 Docker 容器的模板
容器:容器是独立运行的一个或一组应用
仓库:用来保存镜像,可以理解为代码控制中的代码仓库
一个仓库中包含多个镜像,以镜像为模板可创建出多个容器,每个容器是独立运行的一个或者一组应用。 容器是镜像的实例,镜像是容器的模板 。
简略:
容器生命周期:run、start/stop/restart、kill、rm、pause/unpause、create、exec
容器操作:ps、inspect、top、attach、events、logs、wait、export、port
容器rootfs:commit、cp、diff
镜像仓库:login/logout、pull、push、search
本地镜像管理:images、rmi、tag、build、history、save、import
info|version:info、version 【docker info/vaersion分别查看系统信息和版本信息】
一:容器
增:
docker create [OPTIONS] IMAGE [COMMAND] [ARG...] #创建一个新的容器但不启动它docker run [OPTIONS] IMAGE [COMMAND] [ARG...] #创建一个新的容器并运行一个命令
进:
docker exec -ti <container name/id> #不会像attach方式因为退出,导致整个容器退出。
docker attach <container name/id> #进入虚拟机,如果从这个stdin中exit,会导致容器的停止。
开启/停止/重启
docker container start/stop/restart <hash>
删:
docker container rm <hash> # 从此机器中移除指定的容器【删除容器时,容器必须是停止状态,否则会报如下错误】docker container rm $(docker container ls -a -q) # 删除所有容器
docker container kill <hash> # 强制关闭指定的容器
查:
docker container ls # 列出所有运行的容器docker container ls -a # 列出所有的容器
docker ps # 查看我们正在运行的容器
docker ps -l # 查询最后一次创建的容器
docker logs <container id> # 查看容器内的标准输出docker logs <container name> # 查看容器内的标准输出
docker port <container name/id> <port> # 查看容器端口的映射情况
docker inspect <container id/name> #查看Docker的底层信息,它会返回一个 JSON 文件记录着 Docker 容器的配置和状态信息
二:镜像
增:
docker build -t friendlyname . # 使用此目录的“Dockerfile”创建镜像docker push 192.168.1.52:5000/zabbix #提交镜像到本地私有
docker pull ubuntu:13.10 # 下载ubuntu:13.10镜像
删:
docker image rm <image id> # 从机器中移除指定镜像docker image rm $(docker image ls -a -q) # 从机器上移除所有镜像
查:
docker image ls -a # 列出机器上所有镜像docker search httpd # 通过 docker search 命令搜索 httpd 来寻找适合我们的镜像
运:
docker run httpd # 使用镜像仓库
#镜像标签
docker tag <image> username/repository:tag # 标签<image>上传到仓库【repository为镜像源名】
docker push username/repository:tag # 上传标记的图像到注册表
docker run username/repository:tag # 从注册表运行映像
三:其他
docker login # 使用您的Docker凭据登录此CLI会话
docker run -d -p 127.0.0.1:4000:80/udp friendlyname # 后台运行"friendlyname" 镜像并将4000 端口映射到80端口
# -P:将容器内部使用的网络端口映射到我们使用的主机上
# -d:让容器在后台运行
# 默认都是绑定 tcp 端口,如果要绑定 UDP 端口,可以在端口后面加上 /udp
docker run ubuntu:15.10 /bin/echo "Hello world" #Docker 以 ubuntu15.10 镜像创建一个新容器,然后在容器里执行 bin/echo "Hello world",然后输出结果。
docker run -d -P --name runoob training/webapp python app.py #对容器镜像重新命名