运维-docker-管理容器

130 阅读1分钟

1 容器-镜像-仓库-daemon-client关系

image.png

2 常用命令

2.1 查看本地镜像

docker images

2.2 搜索镜像

docker search centos

2.3 拉取镜像

docker pull centos:centos7 注意:centos:latest 拉取的是centos8,里面yum源都是错误,没必要浪费时间。

移除某个镜像

docker rmi [镜像名称]

docker rmi centos:latest

image.png

2.4 启动容器

含义:docker管理器,启动bash命令系统,根据centos这个镜像的latest版本,并且命名别名为c1,且开启terminal与这个bash交互(interactive)。

docker run -it --name=c1 centos:centos7 /bin/bash

2.5 简单测试docker启动的centos7

1 容器外查看docker的网段,commad ifconfig

image.png

2.容器内查看IP hostname -I

print IP: 172.0.0.2

3.在容器内安装httpd服务器

yum -y install httpd
cd /usr/sbin/httpd -k start

4.生成html文档 eche "hello world" /var/www/html/index.html

5.检测,在容器内外访问网页 curl http://172.0.0.2

print context: hello world

6.退出centos,并关闭 exit

2.6 查看所有的容器

docker ps --all

2.7 启动某个容器

docker start [容器别名]

2.8 容器中的命令行附加到当前终端来

docker attach [容器别名]

2.9 移除某个容器

docker rm [容器ID]