Docker 支持如下 Ubuntu 系統:html
本頁內容指引你安裝使用由Docker管理的正式包和管理包. 使用這些安裝包能確保你安裝 Docker最新發行包. 若是你想安裝並使用Ubuntu管理提供的軟件包, 參照Ubuntu文檔.node
備註: Ubuntu Utopic 14.10 和 15.04 依舊在 Docker’s
APT
倉庫中,但再也不提供官方技術支持.linux
Docker要求是64位Ubuntu(不管哪一個版本)。另外,內核必須在最小爲3.10。3.10最新版本或更新的版本也行。web
3.10以前版本缺乏docker運行所須要的特徵一些容器。這些老版本的bug,常常致使數據損失。docker
使用命令: uname -r
來顯示內核版本:shell
$ uname -r 3.11.0-15-generic
備註: 若是你以前安裝過Docker 使用的
APT
, 確保升級你的APT
源 到 Docker新版.ubuntu
APT
源Docker’s APT
倉庫 包括 Docker 1.7.1 及更高版本. 爲了設定 APT
使用最新倉庫的軟件包,:架構
使用 sudo
or root
權限登錄計算機.app
打開 terminal window(命令窗口).socket
更新安裝包信息, 確保 APT 使用 https
協議, 同時CA 證書已經被安裝.
$ sudo apt-get update $ sudo apt-get install apt-transport-https ca-certificates
添加新的GPG
key.
$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
用編輯器打開 /etc/apt/sources.list.d/docker.list
.
若是不存在,則新建一個
刪除任何現有輸入.
添加與您Ubuntu操做系統相關條目。
該條目能夠是:
On Ubuntu Precise 12.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-precise main
On Ubuntu Trusty 14.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-trusty main
Ubuntu Wily 15.10
deb https://apt.dockerproject.org/repo ubuntu-wily main
Ubuntu Xenial 16.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-xenial main
注意:經過命令lsb_release -c查看上面對應的版本,不要都添加上
Codename: trusty
查看Ubuntu的版本號
在終端中執行下列指令:
cat /etc/issue
能夠查看當前正在運行的 Ubuntu 的版本號。其輸出結果相似下面的內容:
Ubuntu 12.04.1 LTS \n \l
方法二
使用 lsb_release 命令也能夠查看 Ubuntu 的版本號,與方法一相比,內容更爲詳細。執行指令以下:
lsb_release -a
將輸出結果:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.1 LTS
Release: 12.04
Codename: precise
備註: Docker沒有爲全部架構提供代碼包 .你能夠找到 nightly built binaries in https://master.dockerproject.org. To install docker on a multi-architecture system, add an
[arch=...]
clause to the entry. 詳細內容參考 Debian Multiarch wiki .
保存並關閉 /etc/apt/sources.list.d/docker.list
file.
或這樣添加docker源
$ echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
更新APT
軟件包索引.
$ sudo apt-get update
清除舊的repo if it exists.
$ sudo apt-get purge lxc-docker
確保 APT
是從正確的代碼庫拉取下來的.
$ apt-cache policy docker-engine
至此,你能夠 使用命令apt-get upgrade
, APT
重新代碼庫拉取代碼.
針對Ubuntu Trusty, Wily, and Xenial, 推薦安裝 the linux-image-extra-*
內核包. linux-image-extra-*
包容許你使用 aufs
存儲驅動.
爲了安裝 linux-image-extra-*
:
打開主機命令窗口.
更新包管理器.
$ sudo apt-get update
安裝推薦包.
$ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
繼續安裝 Docker.
針對Ubuntu Precise, Docker 要求是 3.13內核. 若是內核版本早於 3.13, 必須更新. 參考以下表格來對比不一樣包對運行環境的要求:
Package | Description |
---|---|
linux-image-generic-lts-trusty | Generic Linux kernel image. This kernel has AUFS built in. This is required to run Docker. |
linux-headers-generic-lts-trusty | Allows packages such as ZFS and VirtualBox guest additions which depend on them. If you didn't install the headers for your existing kernel, then you can skip these headers for the"trusty" kernel. If you're unsure, you should include this package for safety. |
xserver-xorg-lts-trusty | Optional in non-graphical environments without Unity/Xorg. Required when running Docker on machine with a graphical environment. To learn more about the reasons for these packages, read the installation instructions for backported kernels, specifically the LTS Enablement Stack — refer to note 5 under each version. |
libgl1-mesa-glx-lts-trusty |
爲了更新linux內核而且安裝附加包, 經過如下步驟:
打開主機命令窗口.
更新包管理器.
$ sudo apt-get update
安裝必需包和可選包
$ sudo apt-get install linux-image-generic-lts-trusty
根據你的運行環境, 你可能須要根據以前提供表格所描述內容安裝其餘內容.
重啓主機.
$ sudo reboot
重啓以後, 繼續安裝Docker.
確保你已經安裝過你的Ubuntu版本所需前提要求.
而後, 經過如下步驟安裝Docker:
用具備sudo權限的用戶登錄
Ubuntu.
Update your APT
package index.
$ sudo apt-get update
安裝 Docker.
$ sudo apt-get install docker-engine
開始使用docker
.
$ sudo service docker start
確認docker
已被正確安裝.
$ sudo docker run hello-world
這個命令下載一個測試圖片而且在容器(container)中運行. 而後容器container運行, 打印出相關信息.說明安裝成功.
下面驅動包含一些可選步驟用來配置Ubuntu環境下Docker.
docker
進程(daemon)綁定在 Unix套接字(socket), 而不是TCP端口(port). 因爲Unix默認是 socket權限歸root用戶全部,其餘用戶能夠經過
sudo訪問
. 由此, docker
進程一般使用root
用戶運行.
爲了不每次使用docker命令都不得不使用sudo
, 建立名爲docker的
Unix group並add users to it. 當docker
daemon 開始,docker
group就會擁有Unix socket 的讀寫權限(read/writable).
警告: The
docker
group is equivalent to theroot
用戶; For details on how this impacts security in your system, 查看Docker Daemon Attack Surface 查看細節.
爲了docker
group and添加用戶user:
使用具備sudo
權限得用戶登陸Ubuntu.
建立docker
group.
$ sudo groupadd docker
添加user到docker
group.
$ sudo usermod -aG docker $USER
Log out and log back in.
This ensures your user is running with the correct permissions.
確認不使用
sudo能夠運行docker
.
$ docker run hello-world
若是提示失敗信息與下面類似:
Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?
檢查 DOCKER_HOST
環境變量 沒有設置shell. 若是這樣,重置他.
When users run Docker, they may see these messages when working with an image:
WARNING: Your kernel does not support cgroup swap limit. WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.
To prevent these messages, enable memory and swap accounting on your system. Enabling memory and swap accounting does induce both a memory overhead and a performance degradation even when Docker is not in use. The memory overhead is about 1% of the total available memory. The performance degradation is roughly 10%.
To enable memory and swap on system using GNU GRUB (GNU GRand Unified Bootloader), do the following:
Log into Ubuntu as a user with sudo
privileges.
Edit the /etc/default/grub
file.
Set the GRUB_CMDLINE_LINUX
value as follows:
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
Save and close the file.
Update GRUB.
$ sudo update-grub
Reboot your system.
If you use UFW (Uncomplicated Firewall) on the same host as you run Docker, you’ll need to do additional configuration. Docker uses a bridge to manage container networking. By default, UFW drops all forwarding traffic. As a result, for Docker to run when UFW is enabled, you must set UFW’s forwarding policy appropriately.
Also, UFW’s default set of rules denies all incoming traffic. If you want to reach your containers from another host allow incoming connections on the Docker port. The Docker port defaults to 2376
if TLS is enabled or 2375
when it is not. If TLS is not enabled, communication is unencrypted. By default, Docker runs without TLS enabled.
To configure UFW and allow incoming connections on the Docker port:
Log into Ubuntu as a user with sudo
privileges.
Verify that UFW is installed and enabled.
$ sudo ufw status
Open the /etc/default/ufw
file for editing.
$ sudo nano /etc/default/ufw
Set the DEFAULT_FORWARD_POLICY
policy to:
DEFAULT_FORWARD_POLICY="ACCEPT"
Save and close the file.
Reload UFW to use the new setting.
$ sudo ufw reload
Allow incoming connections on the Docker port.
$ sudo ufw allow 2375/tcp
Systems that run Ubuntu or an Ubuntu derivative on the desktop typically use127.0.0.1
as the default nameserver
in /etc/resolv.conf
file. The NetworkManager also sets up dnsmasq
to use the real DNS servers of the connection and sets up nameserver 127.0.0.1
in /etc/resolv.conf
.
When starting containers on desktop machines with these configurations, Docker users see this warning:
WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
The warning occurs because Docker containers can’t use the local DNS nameserver. Instead, Docker defaults to using an external nameserver.
To avoid this warning, you can specify a DNS server for use by Docker containers. Or, you can disable dnsmasq
in NetworkManager. Though, disablingdnsmasq
might make DNS resolution slower on some networks.
The instructions below describe how to configure the Docker daemon running on Ubuntu 14.10 or below. Ubuntu 15.04 and above use systemd
as the boot and service manager. Refer to control and configure Docker with systemd to configure a daemon controlled by systemd
.
To specify a DNS server for use by Docker:
Log into Ubuntu as a user with sudo
privileges.
Open the /etc/default/docker
file for editing.
$ sudo nano /etc/default/docker
Add a setting for Docker.
DOCKER_OPTS="--dns 8.8.8.8"
Replace 8.8.8.8
with a local DNS server such as 192.168.1.1
. You can also specify multiple DNS servers. Separated them with spaces, for example:
--dns 8.8.8.8 --dns 192.168.1.1
Warning: If you’re doing this on a laptop which connects to various networks, make sure to choose a public DNS server.
Save and close the file.
Restart the Docker daemon.
$ sudo service docker restart
Or, as an alternative to the previous procedure, disable dnsmasq
in NetworkManager (this might slow your network).
Open the /etc/NetworkManager/NetworkManager.conf
file for editing.
$ sudo nano /etc/NetworkManager/NetworkManager.conf
Comment out the dns=dnsmasq
line:
dns=dnsmasq
保存並關閉.
重啓NetworkManager 和 Docker.
$ sudo restart network-manager $ sudo restart docker
Ubuntu uses systemd
as its boot and service manager 15.04
onwards andupstart
for versions 14.10
and below.
For 15.04
and up, to configure the docker
daemon to start on boot, run
$ sudo systemctl enable docker
For 14.10
and below the above installation method automatically configuresupstart
to start the docker daemon on boot
使用apt-get來安裝Docker最新版:
$ sudo apt-get upgrade docker-engine
卸載Docker包:
$ sudo apt-get purge docker-engine
卸載Docker包及依賴:
$ sudo apt-get autoremove --purge docker-engine
上面命令會刪除images, containers, volumes, user created configuration files on your host. If you wish to delete all images, containers, and volumes run the following command:
$ rm -rf /var/lib/docker
You must delete the user created configuration files manually.
參考:
http://www.cnblogs.com/zzcit/p/5845717.html
http://lizhenliang.blog.51cto.com/7876557/1728931
sudo service docker start 出現如下錯誤解決辦法
Note: There were multiple problems reported when applying the change on some installations. I particularly discourage to do this on a non-virtual machine! If you still want to give this fix a try, make sure you have a snapshot/backup!
This is another remind me blog entry: If you suffer from above message, then you are probably using Ubuntu in a virtual machine. If so, you will need to modify initctl to simply return true using the following steps. First, you need to tell dpkg, that you are going to change the upstart package installation using:
sudo dpkg-divert --local --rename --add /sbin/initctl
Then, you need to create a dummy initctl as a link to true:
ln -s /bin/true /sbin/initctl
參考:
https://www.nesono.com/node/368
重點參考:
Ubuntu16.04安裝Docker1.12+開發實例+hello world+web應用容器 http://blog.csdn.net/dream_an/article/details/51985170 https://docs.docker.com/engine/installation/linux/ubuntu/