Docker-第一次作业

Docker-第一次作业
1.安装docker服务
(1)查看阿里云的yum安装方式

https://developer.aliyun.com/mirror/docker
#step 1: 安装必要的一些系统工具 sudo yum install -y yum-utils device-mapper-persistent-data lvm2
#Step 2: 添加软件源信息 sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#Step 3: 更新并安装Docker-CE sudo yum makecache fast sudo yum -y install docker-ce
#Step 4: 开启Docker服务 sudo service docker start
#注意:
#官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。
#vim /etc/yum.repos.d/docker-ee.repo
#将[docker-ce-test]下方的enabled=0修改为enabled=1

#安装指定版本的Docker-CE:
#Step 1: 查找Docker-CE的版本:
#yum list docker-ce.x86_64 --showduplicates | sort -r
#Loading mirror speeds from cached hostfile
#Loaded plugins: branch, fastestmirror, langpacks docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
#docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable
#docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
#Available Packages
#Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
#sudo yum -y install docker-ce-[VERSION]

(2)开始安装

[[email protected] ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[[email protected]~]#yum-config-manager–add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[[email protected] ~]# yum makecache fast //添加缓存文件
[[email protected] ~]# yum -y install docker-ce
[[email protected] ~]# systemctl enable --now docker
[[email protected] ~]# docker version

Docker-第一次作业Docker-第一次作业
(3)安装镜像加速器

[[email protected] ~]# vim /etc/docker/daemon.json

Docker-第一次作业

[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl
restart docker

2.下载系统镜像(Ubuntu、 centos)
(1)下载镜像

[[email protected] ~]# docker pull ubuntu
[[email protected] ~]# docker pull
jdeathe/centos-ssh

3.基于下载的镜像创建两个容器 (容器名一个为自己名字全拼,一个为首名字字母)

[[email protected] ~]# docker run -d --name puhaiyan ubuntu
[[email protected]~]# docker run -d --name PHY ubuntu

4.容器的启动、 停止及重启操作

[[email protected] ~]# docker run -d jdeathe/centos-ssh //运行容器
[[email protected] ~]# docker stop 0913992af227 //停止容器
0913992af227
[[email protected] ~]# docker start 0913992af227 //重启 0913992af227

5.怎么查看正在运行的容器和所有容器?
(1)运行的

[[email protected] ~]# docker ps

Docker-第一次作业
(2)所有的

[[email protected] ~]# docker ps -a

6.怎么退出容器: 两种方法分别实现?

(1) [[email protected] ~]# docker run -it ubuntu //直接退出
退出后仍运行 Exit+p+q

Docker-第一次作业

(2) [[email protected] ~]# docker run -d ubuntu //退出放在后台运行

7.怎么连接到运行的容器?

(1)[[email protected] ~]# docker run -it ubuntu
(2)[[email protected] ~]# docker
run -d ubuntu

8.查看容器或镜像的内部信息?

[[email protected] ~]# docker image inspect ubuntu:latest

9.如何查看所有镜像?
[[email protected] ~]# docker image ls
Docker-第一次作业