1. 程式人生 > >centos安裝docker之hello-world

centos安裝docker之hello-world

一,配置國內映象(如阿里雲)

1,備份原來的yum源 sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak;

2,設定阿里雲的yum源 sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo;

3,新增epl源 EPEL(http://fedoraproject.org/wiki/EPEL)是由 Fedora 社群打造,為 RHEL 及衍生髮行版如 CentOS、Scientific Linux 等提供高質量軟體包的專案。裝上 EPEL後,可以像在 Fedora 上一樣,可以通過 yum install package-name,安裝更多軟體。sudo wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo;

4,清理快取並生成新的快取 sudo yum clean all ;sudo yum makecache;

二,安裝docker

1,解除安裝docker舊版本

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

2,安裝相關工具類

sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

3,配置docker倉庫

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

4,安裝

sudo yum install docker-ce

三,驗證安裝

1,啟動docker

 sudo systemctl start docker

2,預設開機啟動 
sudo systemctl enable docker

3,啟動hello-world

sudo docker run hello-world

注意:如果啟動helloworld報錯,可能是無法訪問官方映象,需要配置國內映象

sudo vim  /etc/docker/daemon.json
{ 
“registry-mirrors”: [“https://registry.docker-cn.com“] 
}

然後重啟docker

systemctl daemon-reload 
systemctl restart docker

四,測試配置結果

1,拉取busybox

sudo docker pull busybox

2,測試拉取的busybox映象

sudo docker run busybox echo “hello world”