在阿里雲主機的Debian操作系統上安裝Docker


因為需要新搭建飯團網站,所以需要在阿里雲的主機上跑數據庫,java環境。
考慮到可擴展性和模塊化,所以准備最近流行的docker技術。Docker —— 從入門到實踐
阿里雲主機1核1G,資源不多,所以就裝debian了。歡迎捐助 😛


## 下面命令都是以root用戶執行

## 查看內核版本
uname -a
# Debian 3.2.0-4 x86_64
## 版本太低了 < 3.8
## 參照 http://docs.docker.com/installation/debian/ 升級內核

deb http://http.debian.net/debian wheezy-backports main
apt-get update
apt-get install -t wheezy-backports linux-image-amd64

## 重啟系統
restart

## 安裝 docker 前,需要安裝 curl
apt-get install curl

## 安裝 docker
curl -sSL https://get.docker.com/ | sh

## 重啟 docker 服務.
service docker restart

## 運行 hello world
docker run hello-world

## 不出意外的話會出現
# FATA[0000] Get http:///var/run/docker.sock/v1.18/containers/json?all=1: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS? 
## 這是docker服務沒有啟動

service docker status
# 會看到
# [FAIL] Docker is not running ... failed!
# 確實沒啟動

## 顯示啟動一下
docker -d 
## 會看到
# INFO[0000] +job serveapi(unix:///var/run/docker.sock)   
# INFO[0000] Listening for HTTP on unix (/var/run/docker.sock) 
# INFO[0000] +job init_networkdriver()                    
# Could not find a free IP address range for interface 'docker0'. Please configure its address manually and run 'docker -b docker0'
# INFO[0000] -job init_networkdriver() = ERR (1)          
# FATA[0000] Shutting down daemon due to errors: Could not find a free IP address range for interface 'docker0'. Please configure its address manually and run 'docker -b docker0'


## 因為阿里雲把所有內網IP都占用了。所以要改下。

vi /etc/network/interfaces
## 把 "up route add -net 172.16.0.0 netmask 255.240.0.0 gw 10.170.191.247 dev eth0" 這一注釋掉(在這一行最前面加'#')
/etc/init.d/networking restart

service docker start
service docker status
## 能看到 docker is running.

docker run hello-world
## 能看到 hello-world 啟動了
# Hello from Docker.
# This message shows that your installation appears to be working correctly.

## 把非管理員用戶添加到docker組,方便使用
useradd -G docker <user_login>

遇到不少坑,總結起來還是看官方文檔靠譜。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM