linux下的docker使用

一、docker安装

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

参考:https://www.runoob.com/docker/ubuntu-docker-install.html

二、docker使用

1、镜像

docker images ls:

123@123-optiplex-7071:~$ sudo docker images ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

docker images:

123@123-optiplex-7071:~$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              7                   7e6257c9f8d8        6 weeks ago         203MB
hello-world         latest              bf756fb1ae65        8 months ago        13.3kB

2、容器

查看系统内全部处于运行状态的容器docker container ls:

123@123-optiplex-7071:~$ sudo docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
0e159c278187        centos:7            "/bin/bash"         16 hours ago        Up 16 hours                             admiring_matsumoto

在Linux中启动容器的命令如下。
$ docker container run -it centos:7 /bin/bash

docker container run告诉Docker daemon启动新的容器。其中-it参数告诉Docker开启容器的交互模式并将读者当前的Shell连接到容器终端。接下来,命令告诉Docker,用户想基于centos:7镜像启动容器。最后,命令告诉Docker,用户想要在容器内部运行哪个进程,对于Linux示例来说是运行Bash Shell。

连接运行中的容器:

123@123-optiplex-7071:~$ sudo docker container exec -it 0e159c278187 bash
[sudo] loongson 的密码:
[root@0e159c278187 /]#

退出容器:Ctrl-PQ组合键,此时只是退出容器,并没有关闭容器,可通过docker container exec进行连接。

停止容器:

123@123-optiplex-7071:~$ sudo docker container stop 0e159c278187
0e159c278187

停止的容器在 sudo docker container ls下不显示,但是$ docker container ls -a会列出停止的容器

123@123-optiplex-7071:~$ sudo docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

123@123-optiplex-7071:~$ sudo docker container ls  -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
0e159c278187        centos:7            "/bin/bash"         19 hours ago        Exited (137) 23 seconds ago                       admiring_matsumoto
4a8867c218f0        centos:7            "/src/RunMe.sh"     27 hours ago        Exited (2) 25 hours ago                           build_linux_toolchain
5ad0b5c9f46c        hello-world         "/hello"            28 hours ago        Exited (0) 28 hours ago                           jovial_fermat
55b5f1ee553c        hello-world         "/hello"            28 hours ago        Exited (0) 28 hours ago                           serene_leavitt

删除容器:

123@123-optiplex-7071:~$ sudo docker container rm 5ad0b5c9f46c
5ad0b5c9f46c

删除的容器5ad0b5c9f46c已经不在列表啦

123@123-optiplex-7071:~$ sudo docker container ls  -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                            PORTS               NAMES
0e159c278187        centos:7            "/bin/bash"         19 hours ago        Exited (137) About a minute ago                       admiring_matsumoto
4a8867c218f0        centos:7            "/src/RunMe.sh"     27 hours ago        Exited (2) 25 hours ago                               build_linux_toolchain
55b5f1ee553c        hello-world         "/hello"            28 hours ago        Exited (0) 28 hours ago   

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Linux)