centos7下Docker安裝

因爲不少項目都須要在特定的環境下才能穩定運行,在網上搜索一番後,以爲Doceker是一個很不錯的容器化平臺,決定學習踩坑,先把Docker安裝上吧.
Docker有兩個版本,社區版(CE),企業版(EE),這裏的是社區版。服務器系統是阿里雲centos7.4。
舊版本的Docker
下列代碼能夠卸載舊版本的Docker和相關的依賴項。linux

$ 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

因爲以前沒安裝過Docker,這步跳過。
安裝Docker CE
使用推薦方法設置Docker的存儲庫並從中進行安裝。
設置存儲庫
安裝所需的包。yum-utils提供了yum-config-manager 效用,並device-mapper-persistent-data和lvm2由須要 devicemapper存儲驅動程序。docker

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

使用如下命令設置穩定存儲庫。即便您還想從邊緣或測試存儲庫安裝構建,您始終須要穩定的存儲庫。ubuntu

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

可選:啓用邊緣和測試存儲庫。這些存儲庫包含在docker.repo上面的文件中,但默認狀況下處於禁用狀態。您能夠將它們與穩定存儲庫一塊兒啓用。centos

$ sudo yum-config-manager --enable docker-ce-edge
$ sudo yum-config-manager --enable docker-ce-test

執行以上命令。bash

安裝Docker CE
執行命令安裝最新版本的Docker CE:服務器

sudo yum install docker-ce

啓動Docker:app

$ sudo systemctl start docker

docker經過運行hello-world 映像驗證是否已正確安裝:ide

$ sudo docker run hello-world

到這一步,會出現下列信息:學習

[root@iZwz98z8juypkza3zpl0c6Z myProject]# 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 ce 安裝成功測試

相關文章
相關標籤/搜索