日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Docker - 在CentOS 7中安装Docker

發布時間:2023/12/10 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Docker - 在CentOS 7中安装Docker 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在CentOS 7中安裝Docker

1-確認系統信息

# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) # uname -a Linux CentOS-7 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

2-安裝docker

# yum -y install docker

3-關閉SELinux和啟動docker服務

關閉SELinux

  • 永久方法:修改/etc/selinux/config文件中設置SELINUX=disabled ,然后重啟。
  • 臨時方法:執行setenforce 0命令設置SELinux成為permissive模式
sudo systemctl status firewalld.service sudo systemctl stop firewalld.service sudo systemctl disable firewalld.service

啟動docker服務
[root@CentOS-7 ~]# systemctl start docker.service

設置自啟動docker服務

[root@CentOS-7 ~]# systemctl enable docker.service Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [root@CentOS-7 ~]# systemctl is-enabled docker.service enabled [root@CentOS-7 ~]#

4-設置docker代理

# vim /etc/sysconfig/docker
根據實際需要添加相應內容

HTTP_PROXY=http://10.144.1.10:8080 #HTTPS_PROXY=https://10.144.1.10:8080 #FTP_PROXY=ftp://10.144.1.10:8080

注意:一般情況下,國內鏡像設置或代理設置,只需要完成一種配置就可以了。

5-重啟docker

# systemctl daemon-reload
# systemctl restart docker

6-安裝驗證

運行官方鏡像hello-world文件

# docker run hello-world Unable to find image 'hello-world:latest' locally Trying to pull repository docker.io/library/hello-world ... latest: Pulling from docker.io/library/hello-world c04b14da8d14: Pull complete Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9 Status: Downloaded newer image for docker.io/hello-world:latestHello 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.3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker Hub account:https://hub.docker.comFor more examples and ideas, visit:https://docs.docker.com/engine/userguide/# # docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/hello-world latest c54a2cc56cbb 5 months ago 1.848 kB

另外一種Docker代理設置方法

修改docker.service文件
# vim /usr/lib/systemd/system/docker.service
在[Service]部分添加如下內容
Environment="HTTP_PROXY=http://10.144.1.10:8080"
Environment="HTTPS_PROXY=https://10.144.1.10:8080"
Environment="FTP_PROXY=ftp://10.144.1.10:8080"

或者,另外創建代理文件

# mkdir /etc/systemd/system/docker.service.d # touch /etc/systemd/system/docker.service.d/proxy.conf # vim /etc/systemd/system/docker.service.d/proxy.conf

增加以下內容
[Service]
Environment="HTTP_PROXY=http://10.144.1.10:8080"
Environment="HTTPS_PROXY=https://10.144.1.10:8080"
Environment="FTP_PROXY=ftp://10.144.1.10:8080"

重啟docker
# systemctl daemon-reload
# systemctl restart docker

檢查docker環境變量是否加載

# systemctl show docker --property Environment Environment=GOTRACEBACK=crash HTTP_PROXY=http://10.144.1.10:8080 HTTPS_PROXY=https://10.144.1.10:8080 FTP_PROXY=ftp://10.144.1.10:8080

示例 - 在CentOS7系統安裝docker并運行鏡像(使用國內鏡像)

[root@CentOS7 ~]# route add default gw 10.0.3.2 [root@CentOS7 ~]# [root@CentOS7 ~]# yum -y install docker [root@CentOS7 ~]# vim /etc/selinux/config [root@CentOS7 ~]# cat /etc/selinux/config |grep "SELINUX=" # SELINUX= can take one of these three values: SELINUX=disabled [root@CentOS7 ~]# [root@CentOS7 ~]# setenforce 0 [root@CentOS7 ~]# [root@CentOS7 ~]# systemctl start docker.service [root@CentOS7 ~]# systemctl enable docker.service Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [root@CentOS7 ~]# systemctl is-enabled docker.service enabled [root@CentOS7 ~]# [root@CentOS7 ~]# sudo mkdir -p /etc/docker [root@CentOS7 ~]# sudo tee /etc/docker/daemon.json <<-'EOF' > { > "registry-mirrors": ["https://t5t8q6wn.mirror.aliyuncs.com"] > } > EOF {"registry-mirrors": ["https://t5t8q6wn.mirror.aliyuncs.com"] } [root@CentOS7 ~]# systemctl daemon-reload [root@CentOS7 ~]# systemctl restart docker [root@CentOS7 ~]# [root@CentOS7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE [root@CentOS7 ~]# [root@CentOS7 ~]# docker run hello-world Unable to find image 'hello-world:latest' locally Trying to pull repository docker.io/library/hello-world ... latest: Pulling from docker.io/library/hello-world 78445dd45222: Pull complete Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7Hello 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.3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:https://cloud.docker.com/For more examples and ideas, visit:https://docs.docker.com/engine/userguide/[root@CentOS7 ~]# [root@CentOS7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/hello-world latest 48b5124b2768 3 months ago 1.84 kB [root@CentOS7 ~]#

轉載于:https://www.cnblogs.com/anliven/p/6202083.html

總結

以上是生活随笔為你收集整理的Docker - 在CentOS 7中安装Docker的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。