1. 程式人生 > >(CentOS 7)Docker:安裝&配置

(CentOS 7)Docker:安裝&配置

安裝docker

說明:此次安裝沒有根據官網安裝教程的步驟進行,而是直接yum install安裝。

  • 安裝docker yum install docker
  • 關閉防火牆 service firewalld stop
  • 啟動服務 service docker start
  • 設定開機啟動 systemctl enable docker

配置docker

說明:swarm是通過Docker api而進行docker管理的,所以需要將docker的rest api啟動。

Centos docker配置檔案位置:/etc/sysconfig/docker 
Ubuntu docker配置檔案位置:/etc/default/docker

  • 修改配置檔案中的內容如下:
<code class="hljs ruleslanguage has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">OPTIONS</span>=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'-H tcp://0.0.0.0:[docker_port] -H unix:///var/run/docker.sock --selinux-enabled'</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

將docker_port換成想要配置且未被佔用的埠號,比如2375.

  • 重啟docker服務
<code class="hljs  has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">service docker restart</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

此時看下ps -ef | grep docker可以看到docker程序的啟動項-H tcp://0.0.0.0:2375