Docket 第三章

1.获取所有docker命令

docker

 

 

 2.查询指定命令具体用法

docker node --help

  

 

 

 

3.通过容器获取ubuntu镜像

[root@qicheng ~]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
6a5697faee43: Pull complete
ba13d3bc422b: Pull complete
a254829d9e55: Pull complete
Digest: sha256:fff16eea1a8ae92867721d90c59a75652ea66d29c05294e6e2f898704bdb8cf1
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

4.ubuntu下启动一个容器,并以命令形式进入

[root@qicheng ~]# docker run -it ubuntu /bin/bash
root@072ddd311a79:/# 

退出镜像exit

root@072ddd311a79:/# exit
exit

5.启动停止运行的容器

[root@qicheng ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                        PORTS               NAMES
072ddd311a79        ubuntu              "/bin/bash"              About a minute ago   Exited (130) 42 seconds ago                       beautiful_bassi
2eb661c9e2d1        ubuntu:15.10        "/bin/sh -c 'while t…"   15 minutes ago       Exited (137) 10 minutes ago                       priceless_easley
163ed15c303f        ubuntu:15.10        "/bin/bash"              17 minutes ago       Exited (0) 15 minutes ago                         charming_ishizaka
5da5d6fc65d7        ubuntu:15.10        "/bin/echo 'Hello wo…"   18 minutes ago       Exited (0) 18 minutes ago                         distracted_noyce
53c7f7da41fe        hello-world         "/hello"                 21 minutes ago       Exited (0) 21 minutes ago                         naughty_lovelace
2d58f7c9d127        ubuntu:15.10        "/bin/bash"              26 minutes ago       Exited (127) 24 minutes ago                       distracted_feistel
1a9d9a661870        ubuntu:15.10        "/bin/echo 'Hello wo…"   33 minutes ago       Exited (0) 33 minutes ago                         eloquent_heyrovsky
37306ab51a95        hello-world         "/hello"                 34 minutes ago       Exited (0) 34 minutes ago                         fervent_bartik
[root@qicheng ~]# docker start 37306ab51a95
37306ab51a95

6.docket容器后台运行 -d

[root@qicheng ~]# docker run -itd --name ubuntu-test ubuntu /bin/bash
41122d2b470ed3d715da9aff4b650590f7bba0796cf8df7cef4581a25221b90e
[root@qicheng ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
41122d2b470e        ubuntu              "/bin/bash"         19 seconds ago      Up 19 seconds                           ubuntu-test

停止容器

docker stop <容器ID>

重启容器 docker restart <容器ID>

7.后台启动情况下访问容器

 

 

[root@qicheng /]# docker attach 41122d2b470e 
root@41122d2b470e:/# 

 

在使用 -d 参数时,容器启动后会进入后台。此时想要进入容器,可以通过以下指令进入:

  • docker attach

  • docker exec:推荐大家使用 docker exec 命令,因为此退出容器终端,不会导致容器的停止。

 

 8.导出导入容器

[root@qicheng /]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
41122d2b470e        ubuntu              "/bin/bash"         7 minutes ago       Up About a minute                       ubuntu-test
[root@qicheng /]# docker export 41122d2b470e  > ubuntu.tar

 

 

 导出快照到本地

导入容器快照

docker import - test/ubuntu:v1

9.删除容器

docker rm -f 37306ab51a95 

清理所有终止状态的容器

docker container prune

 

posted @ 2020-11-24 15:52  启程华夏  阅读(93)  评论(0编辑  收藏  举报