參考官方文檔:https://docs.docker.com/install/linux/docker-ce/centos/linux
環境介紹docker
系統版本:CentOS Linux release 7.5.1804 (Core) 內核版本:Linux localhost.localdomain 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
安裝前準備工做:json
卸載清理原有docker程序(若是以前沒安裝過docker能夠不用執行)ubuntu
$ 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
安裝依賴軟件(yum-utils提供yum-config-manager包,用來管理yum配置文件;lv2和device-mapper-persistent-data爲dockerdevicemapper存儲設備的必須依賴) vim
$ sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2
添加docker-ce安裝源centos
$ sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
默認開啓的是stable穩定版倉庫,若是想要安裝test測試版或者是邊緣版本可以使用以下命令開啓相關模式,關閉的話只須要將--enable參數換成--disablebash
$ sudo yum-config-manager --enable docker-ce-edge $ sudo yum-config-manager --enable docker-ce-test
開始安裝:app
安裝docker-CE(默認安裝的是最新版本的穩定版)dom
$ sudo yum install docker-ce
若是要安裝特定版本的docker-CE請使用以下命令格式:ide
$ sudo yum install docker-ce-<VERSION STRING>
查看版本列表請使用以下命令:
$ yum list docker-ce --showduplicates | sort -r
配置:
配置docker服務開機啓動
$ sudo systemctl enable docker
配置鏡像加速器:(docker的配置文件爲/etc/docker/daemon.json,默認沒有daemon.json,須要手動建立,鏡像加速地址我用的是阿里雲的)
$ sudo echo {"registry-mirrors": ["你的鏡像地址"]} > /etc/docker/daemon.json $ sudo systemctl daemon-reload
使用dcoker:
啓動docker
$ sudo systemctl start docker
運行第一個容器:
$ sudo docker run hello-world
該命令會自動下載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/get-started/
問題彙總:
1.報錯」WARNING: IPv4 forwarding is disabled. Networking will not work「
緣由:未開啓ipv4轉發
解決辦法:
#編輯文件 vim /etc/sysctl.conf #配置轉發 net.ipv4.ip_forward=1 #重啓服務,讓配置生效 systemctl restart network #查看是否成功,若是返回爲「net.ipv4.ip_forward = 1」則表示成功 sysctl net.ipv4.ip_forward