1. 程式人生 > >阿里雲Ubuntu環境搭建Docker服務

阿里雲Ubuntu環境搭建Docker服務

經過昨天和今天的不斷奮戰,在阿里雲裡面搭建Docker並不容易。所以我覺得有必要記錄下來,以供後人學習。以及我自己的回顧。

首先,檢視我們的系統版本

cat /etc/issue
的到的輸出是
Ubuntu 12.04.1 LTS \n \l
我們順便看一下核心版本,因為Docker需要在3.8以上執行。
uname -r
可以得到你的核心版本,我因為要裝docker,所以按照docker官網的步驟升級了核心,所以輸出是:
3.8.0-44-generic
docker 的Ubuntu安裝說明在:https://docs.docker.com/installation/ubuntulinux/

如何升級核心?

升級核心的步驟其實很簡單,根據Docker官網提供的就好:

指令如下:

# install the backported kernel
$ sudo apt-get update
$ sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring

# install the backported kernel and xorg if using Unity/Xorg
$ sudo apt-get install --install-recommends linux-generic-lts-raring xserver-xorg-lts-raring libgl1-mesa-glx-lts-raring

# reboot
$ sudo reboot

需要重啟。

更新安裝源

我在執行apt-get install docker.io的時候,總是提示找不到,所以說明我的安裝源出了問題,所以,有必要說明如何搞定安裝源,讓我們的過程無錯進行。

首先,備份源列表

cp /etc/apt/sources.list /etc/apt/sources.list_backup
然後,用vim 開啟 源列表檔案。
vim /etc/apt/sources.list
清空裡面的已有列表,然後,我們選擇阿里雲列表,因為我們是阿里雲伺服器嘛。

阿里雲源列表如下:

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

然後執行更新命令
apt-get update
這個時候會出現公鑰問題

提示的錯誤類似如下:

W: There is no public key available for the following key IDs:
8B48AD6246925553
於是,我們又得解決這個問題。

執行如下命令:

apt-get install debian-keyring debian-archive-keyring && sudo apt-key update
apt-key adv --recv-key --keyserver keyserver.ubuntu.com 8B48AD6246925553

上述命令,的那個數字要換成你的,親。

然後,再次執行apt-get update。發現可以了。沒有問題。

於是,我們又回到“正事”,安裝docker

apt-get install docker.io

這次順利的完成了安裝。

開啟服務

[email protected]:/etc/apt# service docker.io restart
stop: Unknown instance: 
docker.io start/running, process 11430


不過接下來還會碰到問題。

 docker run -i -t ubuntu /bin/bash
2014/10/15 11:31:30 Cannot connect to the Docker daemon. Is 'docker -d' running on this host?


這個問題,下節繼續。