sh -c "echo deb https://get.docker.com/ubuntu docker main>/etc/apt/sources.list.d/docker.list"
5、更新APT包索引。
$ sudo apt-get update
6、如果旧的repo存在则清除,第一次安装可以跳过
$ sudo apt-get purge lxc-docker 7、安装
apt-get install lxc-docker
8、启动docker
sudo service docker start
9、验证docker被正确安装
$ sudo docker run hello-world
该命令会向容器中下载一个测试镜像并且运行它。当容器运行成功,就会打印一个信息,然后退出。
bobo@bobo:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
03f4658f8b78: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
Status: Downloaded newer image for hello-world:latest
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.
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 Hub account:
https://hub.docker.com
For more examples and ideas, visit:
https://docs.docker.com/userguide/
Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?
检查DOCKER_HOST环境变量是否被设置,如果为设置,则重新设置。 调整内存和交换分区
当用户运行Docker的时候,当运行一个镜像的时候,他们可能会看到下面这些信息:
WARNING: Your kernel does not support cgroup swap limit. WARNING: Your
kernel does not support swap limit capabilities. Limitation discarded.
为了阻止这些信息,就需要使能你系统上的内存和交换分区(memory and swap accounting)。使能内存和交换分区能够引起内存开销和降解性能,即使Docker并没有在使用。内存开销大约是所有可用内存的1%。性能大约降解10%。
为了在使用GNU GRUB的系统上使能内存和交换分区,遵循下面的步骤:
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]
该警告的出现是因为Docker容器不能使用本地的DNS域名服务器。Docker默认使用一个外部的域名服务器。
为了避免这个警告,你可以指定一个DNS服务器让Docker容器来使用。或者是,你可以在网络管理器中禁用dnsmasq。不过,禁用dnsmasq可能会导致DNS在一些网络中变慢。
下面的指令描述了如何配置运行在Ubuntu14.10或较低版本的上的Docker域。Ubuntu 15.04和更高版本使用systemd作为启动和服务管理器。有关与systemd的配置可以参考这篇文章,control and configure Docker with systemd。
为了指定一个DNS服务器让Docker使用: