欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

docker的常用命令(二)

程序员文章站 2022-04-19 08:53:01
...

容器的基本命令
有了镜像才可以玩容器,所以我们先下载一个容器,就下一个centos的吧~

docker pull centos
[aaa@qq.com ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
8a29a15cefae: Pull complete 
Digest: sha256:fe8d824220415eed5477b63addf40fb06c3b049404242b31982106ac204f6700
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[aaa@qq.com ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              470671670cac        4 months ago        237MB

创建一个容器并启动ta

docker run -it centos /bin/bash

docker的常用命令(二)

docker ps  # 列出容器
[aaa@qq.com ~]# docker run -it centos /bin/bash
[aaa@qq.com /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[aaa@qq.com /]# exit
exit
[aaa@qq.com ~]# docker run -it centos /bin/bash
[aaa@qq.com /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[aaa@qq.com /]# [aaa@qq.com ~]# 
[aaa@qq.com ~]# docker ps -a # 列出当前正在运行的容器 还有你历史运行过的
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
0def9925d52c        centos              "/bin/bash"         17 seconds ago      Up 17 seconds                                   upbeat_nightingale
2975eab5777c        centos              "/bin/bash"         8 minutes ago       Exited (0) 21 seconds ago                       funny_jang
8657356bca8e        fce289e99eb9        "/hello"            20 hours ago        Exited (0) 20 hours ago                         amazing_murdock
b9073ccbe41b        fce289e99eb9        "/hello"            39 hours ago        Exited (0) 39 hours ago                         bold_hertz
d29ba9e2eefa        fce289e99eb9        "/hello"            5 weeks ago         Exited (0) 5 weeks ago                          objective_goodall
[aaa@qq.com ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
0def9925d52c        centos              "/bin/bash"         24 seconds ago      Up 23 seconds                           upbeat_nightingale

docker的常用命令(二)
exit是直接退出了
使用 ctrl + p +q ta还在后台运行
删除容器:

docker rm id
docker rm -f $(docker ps -aq)  删所有
[aaa@qq.com ~]# docker run -it centos /bin/bash
[aaa@qq.com /]# 
[aaa@qq.com /]# [aaa@qq.com ~]# 
[aaa@qq.com ~]# 
[aaa@qq.com ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
6e43b7bdb03d        centos              "/bin/bash"         29 seconds ago      Up 28 seconds                           pensive_shtern
[aaa@qq.com ~]# docker rm 6e43b7bdb03d
Error response from daemon: You cannot remove a running container 6e43b7bdb03d5bbae98316a632c346abdb8020a72c8eb0db27c7bcd13da0153c. Stop the container before attempting removal or force remove
[aaa@qq.com ~]# docker stop 6e43b7bdb03d
6e43b7bdb03d
[aaa@qq.com ~]# docker rm 6e43b7bdb03d
6e43b7bdb03d

启动和停止容器:

docker start id 启动
docker restart id 重启
docker stop id  停止i
docker kill id 杀死
# 和Linux 基础命令比较相似