docker 常用命令
中文社区官网: https://www.docker.org.cn/index.html
学习文档:http://c.biancheng.net/view/3124.html
docker:镜像地址 https://hub.docker.com/
docker -h命令详解:
docker -help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers--容器的自给自足运行时
Options:
--config string Location of client config files (default "/root/.docker") --客户端配置文件的位置(默认“/root/.docker”)
-D, --debug Enable debug mode --启用调试模式
-H, --host list Daemon socket(s) to connect to --服务sockets连接
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")--设置日志级别("debug"|"info"|"warn"|"error"|"fatal")(默认为"info")
--tls Use TLS; implied by --tlsverify --使用TLS;暗示了——tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")--仅由该CA签署的信任证书(默认为“/root/.docker/ CA .pem”)
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")--TLS证书文件路径(默认为/root/.docker/cert.pem)
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")--TLS密钥文件路径(默认为/root/.docker/key.pem)
--tlsverify Use TLS and verify the remote--使用TLS和验证远程
-v, --version Print version information and quit打印版本信息并退出
Management Commands:
checkpoint Manage checkpoints
config Manage Docker configs 配置
container Manage containers --容器
image Manage images--镜像
network Manage networks
node Manage Swarm nodes 群结点
plugin Manage plugins 插件
secret Manage Docker secrets
service Manage services 服务
stack Manage Docker stacks 堆
swarm Manage Swarm 群
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes 容量
Commands:
attach Attach local standard input, output, and error streams to a running container--将本地标准输入、输出和错误流附加到正在运行的容器
build Build an image from a Dockerfile--从Dockerfile构建一个映像
commit Create a new image from a container's changes--根据容器的更改创建新映像
cp Copy files/folders between a container and the local filesystem--Copy files/folders between a container and the local filesystem
create Create a new container创建一个新的容器
diff Inspect changes to files or directories on a container's filesystem--检查对容器文件系统上的文件或目录的更改
events Get real time events from the server--从服务器获取实时事件
exec Run a command in a running container--在正在运行的容器中运行命令
export Export a container's filesystem as a tar archive--将容器的文件系统导出为tar存档
history Show the history of an image--显示镜像的历史
images List images--镜像列表
import Import the contents from a tarball to create a filesystem image --从tarball中导入内容以创建文件系统映像
info Display system-wide information--显示整个系统的信息
inspect Return low-level information on Docker objects--返回Docker对象的低级信息
kill Kill one or more running containers--终止一个或多个正在运行的容器
load Load an image from a tar archive or STDIN --从tar归档文件或STDIN加载映像
login Log in to a Docker registry--登录到Docker注册表
logout Log out from a Docker registry--登出到Docker注册表
logs Fetch the logs of a container--获取一个容器的日志
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 one or more containers--重启一个或多个容器
rm Remove one or more containers--移除一个或多个容器
rmi Remove one or more images--移除一个或多个镜像
run Run a command in a new container--在新容器中运行命令
save Save one or more images to a tar archive (streamed to STDOUT by default)--将一个或多个映像保存到tar存档(默认情况下流到STDOUT)
search Search the Docker Hub for images--在Docker Hub中搜索镜像
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--停止一个或多个停止的容器
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE--创建一个指向SOURCE_IMAGE的标记TARGET_IMAGE
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 Show the Docker version information--显示Docker版本信息
wait Block until one or more containers stop, then print their exit codes--阻塞直到一个或多个容器停止,然后打印它们的退出代码
docker常用命令:
-
一旦容器从镜像启动后,二者之间就变成了互相依赖的关系,并且在镜像上启动的容器全部停止之前,镜像是无法被删除的。尝试删除镜像而不停止或销毁使用它的容器,会导致出错。
启动创建:docker run 或者docker create
启动:docker start nginx
停止:docker stop nginx
-
docker images 查看镜像
-
docker network ls 查看docker 网络
docker network inspect命令就是一个信息宝藏。推荐各位小伙伴仔细阅读该命令的输出内容。
-
docker ps 查看运行情况
docker run -dit -p i: 交互式操作。 -t: 终端。 -d 参数时,容器启动后会进入后台。此时想要进入容器,可以通过以下指令进入: -e 设置环境变量 -P:将容器内部使用的网络端口随机映射到我们使用的主机上。5051:5050 本地端口:容器端口 -v 绑定挂载目录 本地路径:容器路径 -v /fastdfs/tracker/:/home/dfs 将本机的/fastdfs/tracker/,挂载到镜像中的/home/dfs目录 --name 容器的名称 --net 指定容器运行的网络 --ip 指定容器的ip -h 设置host主机的名称 --memory 限制容器可以使用的内存,如果没有指定 --memory-swap 那么默认和--memory一样大
拉取镜像
docker pull ubuntu:13.10
进入容器: 退出容器 exit
docker exec -it 243c32535da7 /bin/bash
删除容器 清理掉所有处于终止状态的容器 :docker container prune
docker rm -f 1e560fca3906
导出容器
docker export 1e560fca3906 > ubuntu.tar
导入镜像 也可以通过指定 URL 或者某个目录来导入
docker import docker import 或docker import http://example.com/exampleimage.tgz example/imagerepo
查看端口绑定情况
docker port adoring_stonebraker 5000
参数来保证每次docker服务重启后容器也自动重启:
--restart=always 例如: docker update --restart=always <CONTAINER ID>
-
移除某个images :docker rmi id 例如:docker rmi 7ce4f91ef623
-
安装docker的脚本: sh install.sh docker-18.06.1-ce.tgz
-
查看docker 的版本 docker -v
-
查看docker的信息:docker system info
-
docker version 命令来检测客户端和服务端是否都已经成功运行,并且可以互相通信。
-
docker container run 命令从镜像来启动容器。
-
ps命令查看当前正在运行的全部进程。 例如 ps -elf
-
docker image pull 是下载镜像的命令。镜像从远程镜像仓库服务的仓库中下载。 默认情况下,镜像会从 Docker Hub 的仓库中拉取。docker image pull alpine:latest 命令会从 Docker Hub 的 alpine 仓库中拉取标签为 latest 的镜像。 Linux Docker 主机本地镜像仓库通常位于 /var/lib/docker/,Windows Docker 主机则是 C:\ProgramData\docker\windowsfilter
举例: docker image pull : 镜像的名字和标签 镜像(采用“:”分隔)
$ docker image pull mongo:3.3.11
//该命令会从官方Mongo库拉取标签为3.3.11的镜像$ docker image pull redis:latest
//该命令会从官方Redis库拉取标签为latest的镜像:如果没有在仓库名称后指定具体的镜像标签,则 Docker 会假设用户希望拉取标签为 latest 的镜像。
-
悬虚(dangling)镜像。$ docker image ls --filter dangling=true
REPOSITORY TAG IMAGE ID CREATED SIZE
4fd34165afe0 7 days ago 14.5MB那些没有标签的镜像被称为悬虚镜像,在列表中展示为:。
docker image build 命令,该命令会构建一个新的镜像,并且标签为 dodge:challenger,同时移除了旧镜像上面对应的标签,旧镜像就变成了悬虚镜像。
docker image prune命令移除全部的悬虚镜像。如果添加了 -a 参数,Docker 会额外移除没有被使用的镜像(那些没有被任何容器使用的镜像)。
-
docker search 命令允许通过 CLI 的方式搜索 Docker Hub。可以通过“NAME”字段的内容进行匹配,并且基于返回内容中任意列的值进行过滤。
返回的镜像中既有官方的也有非官方的。读者可以使用 --filter “is-official=true”,使命令返回内容只显示官方镜像。
例如:docker search alpine --filter “is-official=true”
自动创建的仓库。 --filter “is-automated=true”
docker search需要注意的最后一点是,默认情况下,Docker 只返回 25 行结果。但是,可以通过指定 --limit 参数来增加返回内容行数,最多为 100
-
docker search
命令允许通过 CLI 的方式搜索 Docker Hub。可以通过“NAME”字段的内容进行匹配,并且基于返回内容中任意列的值进行过滤。