一种简单的方式掌握命令行
docker是典型的C/S架构,客户端使用命令行和Rest接口来操作服务端。
命令行格式为:docker [options] command [arg...]
docker 可选的操作 命令 可选的参数
- 查看docker所有命令,
docker --help
- 查看具体的某个命令,
docker command --help
示例:
## 查看帮助命令
docker --help
## 命令行格式
Usage: docker [OPTIONS] COMMAND [arg...]
docker [ --help | -v | --version ]
A self-sufficient runtime for containers.
# 操作
Options:
--config=~/.docker 客户端配置文件 Location of client config files
-D, --debug 启用debug模式 Enable debug mode
-H, --host=[] 服务端域名 Daemon socket(s) to connect to
-h, --help 使用帮助 Print usage
-l, --log-level=info 设置日志级别 Set the logging level
--tls 启用Transport Layer Security传输层安全性协议 Use TLS; implied by --tlsverify
--tlscacert=~/.docker/ca.pem Trust certs signed only by this CA
--tlscert=~/.docker/cert.pem Path to TLS certificate file
--tlskey=~/.docker/key.pem Path to TLS key file
--tlsverify Use TLS and verify the remote
-v, --version 打印版本信息 Print version information and quit
Commands:
attach 进入一个运行中的容器 Attach to a running container
build 由Dockerfile构建一个镜像 Build an image from a Dockerfile
commit 由容器的修改创建一个新的镜像,就是把当前所有操作保存为一个镜像 Create a new image from a container's changes
cp 在容器和本地文件系统之间拷贝文件/目录 Copy files/folders between a container and the local filesystem
create 创建一个新的容器 Create a new container
diff 检查容器文件系统上的更改 Inspect changes on a container's filesystem
events 从server获取实时的事件 Get real time events from the server
exec 在一个运行中的容器上运行一条命令 Run a command in a running container
export 将容器的文件系统导出为tar存档 Export a container's filesystem as a tar archive
history 展示镜像的历史 Show the history of an image
images 列出镜像 List images
import 从tarball导入内容以创建文件系统映像 Import the contents from a tarball to create a filesystem image
info 显示系统范围的信息 Display system-wide information
inspect 返回容器、图像或任务的低级信息 Return low-level information on a container, image or task
kill 杀死一个或多个运行中的容器 Kill one or more running containers
load 从tar存档或STDIN加载镜像 Load an image from a tar archive or STDIN
login 登陆docker镜像仓库 Log in to a Docker registry.
logout 登出docker镜像仓库 Log out from a Docker registry.
logs 拉取容器的日志 Fetch the logs of a container
network 管理docker网络 Manage Docker networks
node 管理Docker Swarm节点 Manage Docker Swarm nodes
pause 暂停一个或多个容器中的所有进程 Pause all processes within one or more containers
port 列出容器的端口映射或特定映射 List port mappings or a specific mapping for the container
ps 列出容器 List containers
pull 拉取一个镜像或仓库从注册仓库 Pull an image or a repository from a registry
push 推送一个镜像或仓库到注册仓库 Push an image or a repository to a registry
rename 重命名一个容器 Rename a container
restart 重启一个容器 Restart a container
rm 删除一个或多个容器 Remove one or more containers
rmi 删除一个或多个镜像 Remove one or more images
run 在一个新的容器一条运行命令 Run a command in a new container
save 保存一个或多个镜像作为一个tar类型的归档文件 Save one or more images to a tar archive (streamed to STDOUT by default)
search 从镜像仓库搜索一个镜像 Search the Docker Hub for images
service 管理docker服务端 Manage Docker services
start 启动一个或多个停止的容器 Start one or more stopped containers
stats 显示容器资源使用统计信息的实时流 Display a live stream of container(s) resource usage statistics
stop 停止一个或多个运行中的容器 Stop one or more running containers
swarm 管理docker swarm Manage Docker Swarm
tag 给一个仓库中的镜像打标签 Tag an image into a repository
top 显示容器中运行的进程 Display the running processes of a container
unpause 取消暂停一个或多个容器中的所有进程 Unpause all processes within one or more containers
update 给一个或多个容器 升级配置Update configuration of one or more containers
version 展示docker的版本信息 Show the Docker version information
volume 管理docker volumes Manage Docker volumes
wait 阻止,直到容器停止,然后打印其退出代码 Block until a container stops, then print its exit code
## 查看具体某个命令的帮助文档
Run 'docker COMMAND --help' for more information on a command.
# 示例
docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
Options:
--add-host value Add a custom host-to-IP mapping (host:ip) (default [])
-a, --attach value Attach to STDIN, STDOUT or STDERR (default [])
--blkio-weight value Block IO (relative weight), between 10 and 1000
--blkio-weight-device value Block IO weight (relative device weight) (default [])
--cap-add value Add Linux capabilities (default [])
--cap-drop value Drop Linux capabilities (default [])
--cgroup-parent string Optional parent cgroup for the container
--cidfile string Write the container ID to the file
--cpu-percent int CPU percent (Windows only)
--cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
-c, --cpu-shares int CPU shares (relative weight)
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
-d, --detach Run container in background and print container ID
--detach-keys string Override the key sequence for detaching a container
--device value Add a host device to the container (default [])
--device-read-bps value Limit read rate (bytes per second) from a device (default [])
--device-read-iops value Limit read rate (IO per second) from a device (default [])
--device-write-bps value Limit write rate (bytes per second) to a device (default [])
--device-write-iops value Limit write rate (IO per second) to a device (default [])
--disable-content-trust Skip image verification (default true)
--dns value Set custom DNS servers (default [])
--dns-opt value Set DNS options (default [])
--dns-search value Set custom DNS search domains (default [])
--entrypoint string Overwrite the default ENTRYPOINT of the image
-e, --env value Set environment variables (default [])
--env-file value Read in a file of environment variables (default [])
--expose value Expose a port or a range of ports (default [])
--group-add value Add additional groups to join (default [])
--health-cmd string Command to run to check health
--health-interval duration Time between running the check
--health-retries int Consecutive failures needed to report unhealthy
--health-timeout duration Maximum time to allow one check to run
--help Print usage
-h, --hostname string Container host name
-i, --interactive Keep STDIN open even if not attached
--io-maxbandwidth string Maximum IO bandwidth limit for the system drive (Windows only)
--io-maxiops uint Maximum IOps limit for the system drive (Windows only)
--ip string Container IPv4 address (e.g. 172.30.100.104)
--ip6 string Container IPv6 address (e.g. 2001:db8::33)
--ipc string IPC namespace to use
--isolation string Container isolation technology
--kernel-memory string Kernel memory limit
-l, --label value Set meta data on a container (default [])
--label-file value Read in a line delimited file of labels (default [])
--link value Add link to another container (default [])
--link-local-ip value Container IPv4/IPv6 link-local addresses (default [])
--log-driver string Logging driver for the container
--log-opt value Log driver options (default [])
--mac-address string Container MAC address (e.g. 92:d0:c6:0a:29:33)
-m, --memory string Memory limit
--memory-reservation string Memory soft limit
--memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)
--name string Assign a name to the container
--network string Connect a container to a network (default "default")
--network-alias value Add network-scoped alias for the container (default [])
--no-healthcheck Disable any container-specified HEALTHCHECK
--oom-kill-disable Disable OOM Killer
--oom-score-adj int Tune host's OOM preferences (-1000 to 1000)
--pid string PID namespace to use
--pids-limit int Tune container pids limit (set -1 for unlimited)
--privileged Give extended privileges to this container
-p, --publish value Publish a container's port(s) to the host (default [])
-P, --publish-all Publish all exposed ports to random ports
--read-only Mount the container's root filesystem as read only
--restart string Restart policy to apply when a container exits (default "no")
--rm Automatically remove the container when it exits
--runtime string Runtime to use for this container
--security-opt value Security Options (default [])
--shm-size string Size of /dev/shm, default value is 64MB
--sig-proxy Proxy received signals to the process (default true)
--stop-signal string Signal to stop a container, SIGTERM by default (default "SIGTERM")
--storage-opt value Storage driver options for the container (default [])
--sysctl value Sysctl options (default map[])
--tmpfs value Mount a tmpfs directory (default [])
-t, --tty Allocate a pseudo-TTY
--ulimit value Ulimit options (default [])
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
--userns string User namespace to use
--uts string UTS namespace to use
-v, --volume value Bind mount a volume (default [])
--volume-driver string Optional volume driver for the container
--volumes-from value Mount volumes from the specified container(s) (default [])
-w, --workdir string Working directory inside the container
你应该对以上命令有个概念和熟悉过程,然后掌握命令行的规则
docker [options] command [arg…]
- 查看帮助文档 docker —help
- 查看具体某个命令的帮助文档 docker command —help
这些才是最重要的!
命令行学习忠告
- 用大于学,多尝试
- 循序渐进,不要想着一次性都背过会用,学会基础的,再慢慢深入,不断复盘
Docker三个最重要的概念,掌握相关的命令行即可满足日常需要。
- 镜像
- 容器
- 仓库
- 另外增加网络连接
接下来讲这三个基础操作,算作命令行入门!