docker命令

Docker进程相关命令

启动Docker服务

systemctl start docker
复制代码

启动Docker服务

中止Docker服务

systemctl stop docker
复制代码

中止Docker服务

重启Docker服务

systemctl restart docker
复制代码

重启Docker服务

查看Docker服务状态

systemctl status docker
复制代码

查看Docker服务状态

开机自启动Docker服务

systemctl enable docker
复制代码

开机自启动Docker服务

镜像相关命令

搜索镜像

# 从网络上查找须要的镜像
docker search 镜像名称
复制代码

拉取镜像

# 从Docker的仓库下载镜像到本地,镜像名称格式为名称:版本号,若是版本号不指定则是最新的版本。若是不知道镜像版本,能够去Docker Hub搜索对应镜像查看便可。
docker pull 镜像名称
复制代码

拉取镜像

查看镜像

# 查看本地镜像
docker images 
复制代码
# 查看本地全部镜像
docker images -a
复制代码
# 查看本地镜像的id
docker images -q
复制代码

查看镜像

删除镜像

# 删除镜像 -f表示强制删除
docker rmi [-f] 镜像id[镜像名称]
复制代码
# 删除全部镜像
docker rmi -f $(docker images -qa)
复制代码

删除镜像

容器相关命令

查看运行的容器

# 查看正在执行的容器
docker ps
复制代码
# 查看全部的容器
docker ps -a
复制代码

查看容器

建立并启动容器

docker run 参数

参数说明:
-i:保持容器运行。经过和-t同时使用。加入-it这两个参数之后,容器建立后会自动进入容器中,退出容器后,容器会自动关闭。
-t:为容器从新分配一个伪输入终端,一般和-i同时使用。
-d:以守护(后台)模式运行容器。建立一个容器在后台运行,须要使用docker exec 进入容器。
-it:建立的容器通常称为交互式容器。
-id:建立的容器通常称为守护式容器、
--name:威建立的容器命名。
-p:映射端口 外部端口:容器内部暴露的端口
复制代码

建立并启动容器

进入容器

docker exec -it 容器id[容器名称] /bin/bash
复制代码

进入容器

查看容器信息

docker inspect 容器id[容器名称]
复制代码

查看容器信息

中止容器

docker stop 容器id[容器名称]
复制代码

中止容器

启动容器

docker start 容器id[容器名称]
复制代码

启动容器

重启容器

docker restart 容器id[容器名称]
复制代码

重启容器

强制中止容器

docker kill 容器id[容器名称]
复制代码

强制中止容器

删除容器

# 须要先中止容器,而后再删除
docker rm 容器id[容器名称]
复制代码
# 强制删除容器
docker rm -f 容器id[容器名称]
复制代码
# 强制删除全部容器
docker rm -f $(docker ps -qa)
复制代码

删除容器

查看容器日志

docker logs -f 容器id[容器名称]
复制代码

查看容器日志

经常使用命令

attach    Attach to a running container                 # 当前 shell 下 attach 链接指定运行镜像
build     Build an im from a Docker registry server          # 从当前 Docker registry 退出
logs      Fetch the logs of a container                 # 输出当前容器日志信息
port      Lookup the public-facing port which is NAT-ed to PRIVATE_PORT    # 查看映射端口对应的容器内部源端口
pause     Pause all processes within a container        # 暂停容器
ps        List containers                               # 列出容器列表
pull      Pull an image or a repository from the docker registry server   # 从docker镜像源服务器拉取指定镜像或者库镜像
push      Push an image or a repository to the docker registry server    # 推送指定镜像或者库镜像至docker源服务器
restart   Restart a running container                   # 重启运行的容器
rm        Remove one or more containers                 # 移除一个或者多个容器
rmi       Remove one or more images             # 移除一个或多个镜像[无容器使用该镜像才可删除,不然需删除相关容器才可继续或 -f 强制删除]
run       Run a command in a new container              # 建立一个新的容器并运行一个命令
save      Save an image to a tar archive                # 保存一个镜像为一个 tar 包[对应 load]
search    Search for an image on the Docker Hub         # 在 docker hub 中搜索镜像
start     Start a stopped containers                    # 启动容器
stop      Stop a running containers                     # 中止容器
tag       Tag an image into a repository                # 给源中镜像打标签
top       Lookup the running processes of a container   # 查看容器中运行的进程信息
unpause   Unpause a paused container                    # 取消暂停容器
version   Show the docker version information           # 查看 docker 版本号
wait      Block until a container stops, then print its exit code   # 截取容器中止时的退出状态值age from a Dockerfile              # 经过 Dockerfile 定制镜像
commit    Create a new image from a container changes   # 提交当前容器为新的镜像
cp        Copy files/folders from the containers filesystem to the host path   #从容器中拷贝指定文件或者目录到宿主机中
create    Create a new container                        # 建立一个新的容器,同 run,但不启动容器
diff      Inspect changes on a container's filesystem   # 查看 docker 容器变化
events    Get real time events from the server          # 从 docker 服务获取容器实时事件
exec      Run a command in an existing container        # 在已存在的容器上运行命令
export    Stream the contents of a container as a tar archive   # 导出容器的内容流做为一个 tar 归档文件[对应 import ]
history   Show the history of an image                  # 展现一个镜像造成历史
images    List images                                   # 列出系统当前镜像
import    Create a new filesystem image from the contents of a tarball # 从tar包中的内容建立一个新的文件系统映像[对应export]
info      Display system-wide information               # 显示系统相关信息
inspect   Return low-level information on a container   # 查看容器详细信息
kill      Kill a running container                      # kill 指定 docker 容器
load      Load an image from a tar archive              # 从一个 tar 包中加载一个镜像[对应 save]
login     Register or Login to the docker registry server    # 注册或者登录一个 docker 源服务器
logout    Log out
复制代码
相关文章
相关标签/搜索