docker安装
1 查看系统内核和系统信息
命令:
uname -r #查看系统内核版本 cat /etc/os-release #查看系统版本
示例:
[root@iZ1608aqb7ntn9Z /]# uname -r 4.18.0-193.14.2.el8_2.x86_64 [root@iZ1608aqb7ntn9Z /]# cat /etc/os-release NAME="CentOS Linux" VERSION="8 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="8" PLATFORM_ID="platform:el8" PRETTY_NAME="CentOS Linux 8 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:8" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-8" CENTOS_MANTISBT_PROJECT_VERSION="8" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="8"
2 开始安装Docker
2.1 卸载旧版本
命令:
yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
示例:
[root@iZ1608aqb7ntn9Z /]# yum remove docker \ > docker-client \ > docker-client-latest \ > docker-common \ > docker-latest \ > docker-latest-logrotate \ > docker-logrotate \ > docker-engine No match for argument: docker No match for argument: docker-client No match for argument: docker-client-latest No match for argument: docker-common No match for argument: docker-latest No match for argument: docker-latest-logrotate No match for argument: docker-logrotate No match for argument: docker-engine 没有软件包需要移除。 依赖关系解决。 无需任何处理。 完毕!
2.2 下载依赖安装包
yum install -y yum-utils
2.3 配置镜像仓库
#国外的地址 yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo # 设置阿里云的Docker镜像仓库 yum-config-manager \ --add-repo \ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
示例:
[root@iZ1608aqb7ntn9Z /]# yum-config-manager \ --add-repo \ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 添加仓库自:https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.rep
2.4 更新yum软件包
yum makecache fast
2.5 下载docker
yum install docker-ce docker-ce-cli containerd.io # 安装社区版 yum install docker-ee docker-ee-cli containerd.io # 安装企业版
一般情况下安装社区版
3 启动Docker
命令:
systemctl start docker # 启动Docker docker version # 查看当前版本号,是否启动成功 systemctl enable docker # 设置开机自启动
示例:
[root@iZ1608aqb7ntn9Z /]# systemctl start docker [root@iZ1608aqb7ntn9Z /]# docker version Client: Docker Engine - Community Version: 20.10.7 API version: 1.41 Go version: go1.13.15 Git commit: f0df350 Built: Wed Jun 2 11:56:24 2021 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.7 API version: 1.41 (minimum version 1.12) Go version: go1.13.15 Git commit: b0f5bc3 Built: Wed Jun 2 11:54:48 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4.9 GitCommit: e25210fe30a0a703442421b0f60afac609f950a3 runc: Version: 1.0.1 GitCommit: v1.0.1-0-g4144b63 docker-init: Version: 0.19.0 GitCommit: de40ad0
4 Docker的HelloWorld
命令:
docker run hello-world
示例:
[root@iZ1608aqb7ntn9Z /]# docker run hello-world Unable to find image 'hello-world:latest' locally # 本地没有 latest: Pulling from library/hello-world # pull一个最新版 b8dfde127a29: Pull complete # pull成功 Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e Status: Downloaded newer image for hello-world:latest Hello from 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/
5 Docker卸载
yum remove docker-ce docker-ce-cli containerd.io # 卸载依赖 rm -rf /var/lib/docker # 删除资源 . /var/lib/docker是docker的默认工作路径
6 配置阿里云镜像
6.1 进入阿里云官网,搜索容器镜像服务
6.2 执行命令
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://axvfsf7e.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程