Docker在Linux下的安装

环境准备

  • CentOS7,查看系统内核版本
[root@centos7 bin]# uname -r
3.10.0-1160.el7.x86_64

安装Docker

查看docker帮助文档,进入get-started
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这里选择的系统根据自己的系统来
在这里插入图片描述

1、卸载旧的版本

[root@centos7 bin]# yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine

2、安装需要的安装包

[root@centos7 bin]# yum install -y yum-utils

3、设置镜像的仓库

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo #国外的镜像地址,比较慢不建议使用
yum-config-manager \
 	--add-repo \
 	http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #替换为国内的镜像加速地址【可以直接搜索docker阿里云镜像加速地址】

4、安装Docker引擎

# 可以先更新软件包的索引
yum makecache fast

[root@centos7 bin]# yum install docker-ce docker-ce-cli containerd.io

如果想安装指定版本,可以参照官方文档去安装指定版本
在这里插入图片描述

5、启动Docker

[root@centos7 bin]# systemctl start docker

6、使用docker version查看是否安装成功

docker version #可以查看docker的版本信息

在这里插入图片描述

7、运行hello-word

[root@centos7 bin]# docker run hello-world
Unable to find image 'hello-world:latest' locally #没有找到hello-word的镜像
latest: Pulling from library/hello-world #去远程拉取镜像
b8dfde127a29: Pull complete
Digest:   sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for hello-world:latest #签名信息,证明拉取成功了

Hello from Docker! #运行镜像,如果出现这句话,就证明docker已经安装成功了
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

docker run 的原理图
在这里插入图片描述

8、查看下载的hello-word镜像

[root@centos7 bin]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED      SIZE
hello-world   latest    d1165f221234   6 days ago   13.3kB

如果需要卸载Docker,可以参考官方文档的卸载步骤
在这里插入图片描述

#  /var/lib/docker   docker的默认工作路径

配置阿里云镜像加速

1、登录阿里云,找到容器镜像服务

2、找到镜像加速地址

在这里插入图片描述

3、配置使用

按照上面的命令步骤一步一步来
1)创建docker文件夹

sudo mkdir -p /etc/docker

2)编写配置文件

sudo tee /etc/docker/daemon.json <<-'EOF'
{
    
    
  "registry-mirrors": ["使用自己阿里云加速地址"]
}
EOF

3)重启服务

sudo systemctl daemon-reload

4)重启docker

sudo systemctl restart docker

配置docker开机自启

systemctl enable docker

猜你喜欢

转载自blog.csdn.net/weixin_44412272/article/details/114687409