高级运维day6-练习

题目

1.安装docker服务,配置镜像加速器
2.下载系统镜像(Ubuntu、 centos)
3.基于下载的镜像创建两个容器 (容器名一个为自己名字全拼,一个为首名字字母)
4.容器的启动、 停止及重启操作
5.怎么查看正在运行的容器和所有容器?
6.怎么退出容器: 两种方法分别实现?
7.怎么连接到运行的容器?
8.查看容器或镜像的内部信息?
9.如何查看所有镜像?

1.安装docker服务,配置镜像加速器

安装软件包

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

设置yum源

[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装

[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
[root@localhost ~]# yum -y install docker-ce-18.03.1.ce

启动docker设置开机自启

[root@sql2 ~]# systemctl start docker
[root@sql2 ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

配置镜像加速器

[rootasql2 ~]# tee /etc/docker/daemon.json <<-'EOF
{
"registry-mirrors": ["https://ep9gag8m.mirror.aliyuncs.com"]
}
EOF
{
"registry-mirrors": ["https://ep9gag8m.mirror.aliyuncs.com"]
}
2.下载系统镜像(Ubuntu、 centos)
[rootasql2 ~]# docker search ubuntu
NAME                               DESCRIPTION
	STARS        OFFICIAL          AUTOMATED
ubuntu      						Ubuntu is a Debian-based Linux operat
	16305		[OK]
websphere-liberty			WebSphere Liberty multi-architecture
	296			[OK]
[rootasql2 -]# docker pull centos:7
7: Pulling from library/centos
2d473bo7cdd5: Pull complete
Digest: sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
Status: Downloaded newer image for centos:7

[root@sql2 ~]# docker pull ubuntu
3.基于下载的镜像创建两个容器 (容器名一个为自己名字全拼,一个为首名字字母)
[root@sql2 ~]# docker run --name yuanting -it ubuntu /bin/bash
root@3ee108fd6ce8:/# exit
[root@sql2 ~]# docker run --name yt -it centos /bin/bash
[root@315cf79e1717 /]# exit
4.容器的启动、 停止及重启操作

启动

[root@sql2 ~]# docker start yuanting
yuanting

停止

[root@sql2 ~]# docker stop yuanting
yuanting

重启

[root@sql2 ~]# docker restart yuanting
yuanting
5.怎么查看正在运行的容器和所有容器?
[rootasgl2 ~]# docker ps
CONTAINER ID		IMAGE		COMMAND		CREATED
  STATUS				  PORTS		NAMES
3ee108fd6ce8		ubuntu		"/bin/bash"			5 minutes ago
  Up About a minute					yuanting

查看所有容器

[root@sql2 ~]# docker ps -a
6.怎么退出容器: 两种方法分别实现?
① [root@sql2 ~]# docker run --name yuanting -it ubuntu /bin/bash
root@3ee108fd6ce8:/# exit

②crtl+q

7.怎么连接到运行的容器?
[root@sql2 ~]# docker exec -it yuanting /bin/bash
root@3ee108fd6ce8:/#
[rootasql2 ~]# docker exec -it yuanting /bin/bash
roota3ee108fd6ce8:/#
8.查看容器或镜像的内部信息?
[root@sql2 ~]# docker inspect yuanting
[
		{
			"Id":"3ee108fd6ce87e274852f7c6fce47aa9cefccla86d42f7ob1",
			"Created":"2023-08-23T03:27:11.747927704Z",
			"Path":"/bin/bash",
			"Args": [],
9.如何查看所有镜像?
[rootasql2 ~]# docker image s
REPOSITORY			TAG			IMAGE ID			CREATED
	SIZE
ubuntu						latest		ba6acccedd29	22 months ago
72.8MB
centos						7				eeb6ee3f44bd	23 months ago
204MB
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值