第六次作业

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
 
查看版本信息并安装docker-ce
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
[root@localhost ~]# yum -y install docker-ce-18.03.1.ce
 
启动docker设置开机自启
[root@localhost ~]# systemctl enable --now docker
[root@localhost ~]# mkdir -p /etc/docker
 
[root@localhost ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://5twf62k1.mirror.aliyuncs.com"]
}
 
重启容器docker (重启 Docker 进程加速器即可生效)
 
[root@localhost ~]# systemctl restart docker
 
验证拉取镜像速度
[root@localhost ~]# docker pull mysql

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

[root@localhost ~]# docker pull ubuntu
[root@localhost ~]# docker pull centos
 
查看镜像
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               latest              3218b38490ce        20 months ago       516MB
ubuntu              latest              ba6acccedd29        22 months ago       72.8MB
centos              latest              5d0da3dc9764        23 months ago       231MB

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

[root@localhost ~]# docker run --name shenqilun -it ubuntu /bin/bash
root@2b772b9b44ed:/# exit
exit
 
[root@localhost ~]# docker run --name SQL -it centos /bin/bash
[root@f76eb823b8b3 /]# exit
exit
 
查看容器
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                            PORTS               NAMES
f76eb823b8b3        centos              "/bin/bash"         46 seconds ago       Exited (0) 40 seconds ago                             SQL
2b772b9b44ed        ubuntu              "/bin/bash"         About a minute ago   Exited (127) About a minute ago                       shenqilun

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

以shenqilun容器为例
 
启动
[root@localhost ~]# docker start shenqilun
shenqilun
 
停止
[root@localhost ~]# docker stop shenqilun
shenqilun
 
重启
[root@localhost ~]# docker restart shenqilun
shenqilun

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

正在运行的容器
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
2b772b9b44ed        ubuntu              "/bin/bash"         4 minutes ago       Up About a minute                       shenqilun
 
所有容器
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
f76eb823b8b3        centos              "/bin/bash"         3 minutes ago       Exited (0) 3 minutes ago                       SQL
2b772b9b44ed        ubuntu              "/bin/bash"         4 minutes ago       Up About a minute                              shenqilun

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

exit

Ctrl+p+q

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

[root@localhost ~]# docker exec -it shenqilun /bin/bash
root@2b772b9b44ed:/# 

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

[root@localhost ~]# docker inspect shenqilun | grep -i address
            "LinkLocalIPv6Address": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "GlobalIPv6Address": "",
            "IPAddress": "172.17.0.2",
            "MacAddress": "02:42:ac:11:00:02",
                    "IPAddress": "172.17.0.2",
                    "GlobalIPv6Address": "",
                    "MacAddress": "02:42:ac:11:00:02",

9.如何查看所有镜像?

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               latest              3218b38490ce        20 months ago       516MB
ubuntu              latest              ba6acccedd29        22 months ago       72.8MB
centos              latest              5d0da3dc9764        23 months ago       231MB

你可能感兴趣的:(eureka,云原生)