【邊玩邊學K8S】【002】安裝Docker

安裝Docker

安裝

[root@host01 ~]# yum makecache
[root@host01 ~]# yum install docker
[root@host01 ~]# yum install golang

啓動

[root@host01 ~]# systemctl enable docker
[root@host01 ~]# systemctl start docker
[root@host01 ~]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-68.gitdded712.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      dded712/1.13.1
 Built:           Tue Jul 17 18:34:48 2018
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-68.gitdded712.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      dded712/1.13.1
 Built:           Tue Jul 17 18:34:48 2018
 OS/Arch:         linux/amd64
 Experimental:    false

配置Docker代理(有條件可選)

Environment="HTTP_PROXY=http://用戶名:密碼@代理IP:端口"
Environment="HTTPS_PROXY=http://用戶名:密碼@代理IP:端口"
Environment="NO_PROXY=localhost,127.0.0.1"

追加代理配置內容到/lib/systemd/system/docker.service中的Environment段的下面linux

重啓

[root@host01 ~]# systemctl daemon-reload
[root@host01 ~]# systemctl restart docker

配置用戶(有條件可選)

[root@host01 ~]# groupadd docker
[root@host01 ~]# usermod -aG docker $USER
非root用戶執行時,須要建立docker用戶組,將當前用戶加入docker用戶組

驗證

[root@host01 ~]# docker run hello-world

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/engine/userguide/

在公司內部進行docker pull時,因爲一般要通過代理,有可能會因爲證書問題致使鏡像沒法pull下來,此時須要如下解決方案git

  1. 獲取公司代理的證書(以Chrome爲例,打開一個能夠打開的外網,打開地址欄的安全按鈕,查看證書詳細信息,複製證書,採用默認格式導出證書便可。)
  2. 將證書更名爲cacert.pem
  3. 將cacert.pem放到CentOS的/etc/pki/ca-trust/source/anchors下
  4. 執行update-ca-trust命令使其生效
相關文章
相關標籤/搜索