docker容器管理

1.查看容器

[root@centos201 ~]# docker ps  # 查看现有的容器列表。
CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS          PORTS     NAMES
6aab26123615   nginx:1.16   "nginx -g 'daemon of…"   52 seconds ago   Up 51 seconds   80/tcp    dazzling_heisenberg
[root@centos201 ~]# 


[root@centos201 ~]# docker  ps -a  # 查看容器运行的所有状态
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                     PORTS     NAMES
cdfe54e8192b   centos:7       "/bin/bash"              9 seconds ago    Exited (0) 8 seconds ago             great_payne
6aab26123615   nginx:1.16     "nginx -g 'daemon of…"   54 seconds ago   Up 53 seconds              80/tcp    dazzling_heisenberg
8b4f7ae36b6e   nginx:1.14.2   "nginx -g 'daemon of…"   3 minutes ago    Exited (0) 2 minutes ago             clever_jones
[root@centos201 ~]# 


[root@centos201 ~]# docker ps -l  # 查看最新一个容器创建的信息。无论该容器处于什么状态均可查看。
CONTAINER ID   IMAGE      COMMAND       CREATED          STATUS          PORTS     NAMES
f2bebb69d4a1   centos:7   "/bin/bash"   30 seconds ago   Up 29 seconds             test
[root@centos201 ~]# 

2.运行容器

[root@centos201 ~]# docker run nginx:1.16  # 将容器放在前台运行
6aab2612361572634a88312c413fb8aedae47951589cf7551d739a54f90e1205

[root@centos201 ~]# docker inspect dfcfd8e9a5d3
 

[root@centos201 ~]# docker run -d nginx:1.16   # 将容器放在后台运行
6aab2612361572634a88312c413fb8aedae47951589cf7551d739a54f90e1205
[root@centos201 ~]# 

[root@centos201 ~]# docker container run -i -t centos:7   # -i表示交互模式,-t表示分配一个终端。
[root@5338d7542d32 /]# 
[root@5338d7542d32 /]# ls /
anaconda-post.log  bin  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@5338d7542d32 /]# 
[root@5338d7542d32 /]# pwd
/
[root@5338d7542d32 /]# 
[root@5338d7542d32 /]# exit
exit
[root@centos201 ~]# 
	
	
[root@centos201 ~]# docker  run -itd --name test01 centos:7   # --name表示给容器起名字。
f2bebb69d4a119e4e2d5a222dfe730a345b8b21d5e6d9c26d9dffb5d48dcc776
[root@centos201 ~]# 


[root@centos201 ~]# docker run -d -p 10.0.0.201:80:80 nginx:1.16  # 将nginx容器的80端口通过10.0.0.201网卡暴露。
732ac37a5f72f6ccc47a9593a84298dfab8bee65ed62688159cdbff963005b28
[root@centos201 ~]# 

3.连接到指定容器

[root@centos201 ~]# docker container exec -it linux bash
[root@f2bebb69d4a1 /]# 

4.删除所有容器

docker container rm -f `docker container ps -qa`

5.查看容器的IP地址,查看IPAddress字段即可

docker container inspect 容器名称|容器的ID
docker container inspect `docker container ps -lq`
posted @ 2024-01-21 21:16  只为心情愉悦  阅读(17)  评论(0编辑  收藏  举报