Docker的安裝
環境准備
- 需要會Linux基礎
- 需要一台CentOS 7
- 需要連接CentOS 7執行指令,並且能聯網
安裝:
連接服務器
查看環境,內核是否為3.8以上的
[root@localhost ~]# uname -a Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
查看系統版本,最好為CentOS 7
[root@localhost ~]# cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
卸載舊版本的Docker,我的因為沒有所以 不會卸載
[root@localhost ~]# yum remove docker \ > docker-client \ > docker-client-latest \ > docker-common \ > docker-latest \ > docker-latest-logrotate \ > docker-logrotate \ > docker-engine ; 已加載插件:fastestmirror 參數 docker 沒有匹配 參數 docker-client 沒有匹配 參數 docker-client-latest 沒有匹配 參數 docker-common 沒有匹配 參數 docker-latest 沒有匹配 參數 docker-latest-logrotate 沒有匹配 參數 docker-logrotate 沒有匹配 參數 docker-engine 沒有匹配 不刪除任何軟件包 [root@localhost ~]#
安裝yum-utils
[root@localhost ~]# yum install -y yum-utils
設置鏡像的倉庫
國外的
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
更新軟件包索引
[root@localhost ~]# yum makecache fast
安裝Docker 引擎 客戶端 容器IO 注意:-ce 代表社區版 -ee是企業版
[root@localhost ~]# yum install docker-ce docker-ce-cli containerd.io
如果需要安裝指定版本的Docker-ce,可以看這個命令
搜索版本 yum list docker-ce --showduplicates | sort -r 指定版本 yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
我直接安裝的最新版
啟動Docker
[root@localhost ~]# systemctl start docker
查看Docker版本,能打印出信息代表Docker安裝成功
[root@localhost ~]# docker version
測試,運行hello-world鏡像
[root@localhost ~]# docker run hello-world Unable to find image 'hello-world:latest' locally 本地沒有找到名字為hello-world:latest的鏡像 latest: Pulling from library/hello-world 去遠程庫拉取鏡像 0e03bdcc26d7: Pull complete 拉取成功 Digest: sha256:95ddb6c31407e84e91a986b004aee40975cb0bda14b5949f6faac5d2deadb4b9 校驗碼 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/
查看本地鏡像
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 13 months ago 13.3kB
到此安裝成功
卸載:
卸載Docker的引擎 cli 和容器
yum remove docker-ce docker-ce-cli containerd.io
主機上的鏡像,容器,卷或自定義配置文件不會自動刪除。要刪除所有圖像,容器和卷
rm -rf /var/lib/docker
作者:彼岸舞
時間:2021\02\18
內容關於:Docker
本文來源於網絡,只做技術分享,一概不負任何責任