Transferred from: http://www.cnblogs.com/lighten/p/6034984.html
This article mainly translates the official guidance Ubuntu installs the Docker guide, the convenient inspection, the official guidance website: https://docs.docker.com/engine/installation/linux/ubuntulinux/. This article mainly guides you to install the use Docker-managed release package and its installation mechanism. Use these packages to make sure you get the latest Docker official release. If you need to install using ubuntu-managed package, consult the Ubuntu documentation.
The 1.docker supports the following Ubuntu operating systems:
Ubuntu xenial 16.04[lts] ubuntu trusty 14.04[lts] ubuntu precise 12.04[lts]
2. Front-facing requirements
Regardless of which version of Ubuntu you are, Docker requires 64 of the operating system. In addition, your kernel kernel must be at least 3.10 versions above. The recent 3.10 iteration or the latest maintenance version is also acceptable. The system before the kernel3.10 version lacks some features to run the Docker container. Some known bugs of these older versions can result in data loss and frequent failures under certain conditions. Check your current version of kernel, open terminal, enter
Uname-r
Note: If you have previously used apt to install Docker, make sure you update the APT source for the new version of the Docker repository.
3. Update your APT source
The APT warehouse for Docker contains 1.7.1 and higher versions. Use the package from the Docker repository by setting apt.
1) Login machine, user must use sudo or root privileges.
2) Open Terminal
3) Update package information to ensure that apt can work with HTTPS and that the CA certificate is installed
sudo apt-get update
sudo apt-get install Apt-transport-https ca-certificates
This problem may occur because another program is running, causing the resource to be locked out. The reason that the resource is locked may be that the last run of the installation or update is not completed properly, the solution is to delete.
sudo rm/var/cache/apt/archives/lock
sudo rm/var/lib/dpkg/lock
4) Add a new GPG key
sudo apt-key adv--keyserver hkp://p80.pool.sks-keyservers.net:80--recv-keys 58118e89f3a912897c070adbf76221572c52609d
5) Find the appropriate key for your Ubuntu operating system, this key determines which package apt will search for. The possible keys are:
Ubuntu version Repository
Precise 12.04 Deb Https://apt.dockerproject.org/repoubuntu-precise main
Trusty 14.04 Deb Https://apt.dockerproject.org/repoubuntu-trusty main
Xenial 16.04 Deb Https://apt.dockerproject.org/repoubuntu-xenial main
Note: Docker does not provide packages for all architectures, Binary artifacts is built nightly, which you can do from https://master.dockerproject.org. Download it here. Install Docker on a multi-architecture system and add a [arch=] clause to the key. For more details, refer to Debian multiarch Wikipedia.
6) Run the following command, replace the key with the placeholder <REPO> for your operating system.
echo "<REPO>" | sudo tee/etc/apt/sources.list.d/docker.list
Like, you're 16.04. <REPO> of the above command
Replace with Deb Https://apt.dockerproject.org/repoubuntu-xenial main executes that command, and in that folder creates a Docker.list file with the contents of
Deb Https://apt.dockerproject.org/repoubuntu-xenial Main
7) Update APT Package index
sudo apt-get update
8) Verify that apt is pulling the installation package from a proper warehouse.
When you run the following command, this key will return the Docker version you currently have installed, with each key including url:https://apt.dockerproject.org/repo/. Here is a partial output of the interception.
Command: Apt-cache policy docker-engine
Now when you run Apt-get upgrade, APT will pull the installation package from the new repository.
4. Pre-operation required for some Ubuntu versions
Ubuntu xenial 16.04[lts] Ubuntu trusty 14.04[lts]
These two versions remember to install the linux-iamge-extra-* kernel package. This package allows you to use the AUFS storage driver.
sudo apt-get install linux-image-extra-$ (uname-r) linux-image-extra-virtual
Ubuntu Precise 12.04[lts]
For this version, you need more than 3.13 kernel version, you must upgrade. The following table guides you on which packages you need:
You can execute the following command:
sudo apt-get install Linux-image-generic-lts-trusty
sudo reboot
5. Installation
1) login system, use your account with sudo full access
2) Update apt package index: sudo apt-get update
3) Installing Docker:sudo apt-get Install Docker-engine
4) Open Docker process: sudo service docker start
5) Verify that Docker is installed successfully: sudo docker run Hello-world
This command downloads a test image and runs in a container. When the container is running, he prints some information and exits.
6. Optional configuration 6.1 Create a docker group
The Docker daemon is the socket of the UNIX that is bound, not the TCP port. By default, the UNIX socket belongs to the user root, and the other user wants to use the sudo command. For this reason, Docker daemon is typically run with the root user.
To avoid using sudo when you use the Docker command, create a UNIX group named Docker and add users. When Docker daemon is started, it allocates UNIX socket read-write permissions to the owning Docker group.
Note: The Docker group is not equivalent to user root, if you want to know more about the security impact, view Docker daemon attack surface.
sudo groupadd Docker
sudo usermod-ag Docker $USER
Exit and re-enter to make sure that the user has the correct permissions.
The checksum takes effect by running the Docker command without Sudo:docker run Hello-world, if the failure has the following similar information: Cannot connect to the Docker daemon. Is ' Docker daemon ' running on this host? Make sure that the DOCKER_HOST environment variable is not set. If there is to cancel it.
6.2 Adjusting the memory and swap area calculations
When users run Docker, they may see the following information when they use a mirror:
Warning:your kernel does not support Cgroup swap limit. Warning:your kernel does not the support swap limit capabilities. limitation discarded.
To block this information, enable memory and swap calculation in your system. This operation can result in memory overhead and performance degradation even if Docker is not used. The memory overhead is roughly 1% of the total memory. Performance is reduced by about 10%.
Modify the/etc/default/grub file. VI or VIM command line, set the value of Grub_cmdline_linux, as follows: grub_cmdline_linux= "Cgroup_enable=memory swapaccount=1". Save the file and close it. sudo update-grub updates the startup item. Reboot reboot your system.
6.3 Starting UFW forwarding
When you run Docker, using UFW (uncomplicated Firewall) on the same host, you need additional configuration. Docker uses bridging to manage the network of containers. By default, UFW discards all forwarding traffic. Therefore, the Docker runtime UFW can be used, and you must set the appropriate UFW forwarding rules.
UFW The default configuration rule denies all incoming traffic. If you want to reach your container from another host, you need to allow ports to connect to Docker. The default port for Docker is 2376 if TLS is enabled, and if no boot is 2375, the session is not encrypted. By default, Docker runs without a TLS boot.
In order to configure the UFW and allow incoming connections to the Docker port:
Check if UFW is installed and enabled: sudo UFW status
Open/ETC/DEFAULT/UFW file and edit: sudo nano/etc/default/ufw
Set default_forward_policy:default_forward_policy= "ACCEPT"
Save exit and restart with new settings: sudo ufw reload
Allows all connections to the Docker port: sudo ufw allow 2375/tcp
6.4 Configuring a DNS server for use with Docker
Ubuntu or Ubuntu derivative products that run on the desktop of the system typically use 127.0.0.1 as the default nameserver file/etc/resolv.conf file. NetworkManager is also usually set DNSMASQ nameserver 127.0.0.1 in/etc/resolv.conf.
When you run a container on a desktop machine and use these configurations, the users of Docker will see these warnings:
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]
This warning occurs because the Docker container cannot use a local DNS naming server. In addition, Docker uses an additional nameserver by default.
To avoid this warning, you can specify a DNS server when using the Docker container. Or you can disable DNSMASQ in NetworkManager. However, disabling causes the DNS protocol to slow down in some networks.
The following instructions describe how to configure the Docker daemon in Ubuntu14.0 or the following versions. Use SYSTEMD on Ubuntu15.04 and above for startup items and service management. Guidance to configure and control a daemon by using SYSTEMD.
To set the specified DNS service:
Open the/etc/default/docker file and edit: sudo nano/etc/default/docker, add configuration entry: docker_opts= "--dns 8.8.8.8". Replace 8.8.8.8 with a local DNS service such as 192.168.1.1. You can also configure multiple DNS servers. Separate them with spaces, such as:--dns 8.8.8.8--dns 192.168.1.1. Warning: Do this when you are connected to a different network in your notebook, making sure to select a common DNS server. Save the file and exit and restart the Docker daemon: sudo service docker restart.
Or another option, disable DNSMASQ in Network Manager, which may cause your speed to slow down:
Open the/etc/networkmanager/networkmanager.conf file and edit it: sudo nano/etc/networkmanager/networkmanager.conf. Find Line DNS=DNSMASQ, comment out. Save close file, restart Network manager and Docker.sudo restart Network-manager sudo restart Docker.
6.5 Configuring Docker Boot Boot
After Ubuntu15.04 use SYSTEMD as boot boot and service management, 14.10 and below are upstart. More than 15.04, you need to configure the Docker daemon boot boot, run command: sudo systemctl enable Docker
The installation method of version 14.10 and below will automatically configure upstart to start Docke daemon on boot.
7 Upgrade Uninstall Docker
Upgrade: sudo apt-get upgrade docker-engine
Uninstall: sudo apt-get purge docker-engine
Uninstall and dependency: sudo apt-get autoremove--purge docker-engine
The above command does not uninstall Images,containers,volumes or the user-created configuration file. If you want to delete these things, execute the following command:
Rm-rf/var/lib/docker
The simplest way to install is: sudo apt-get update sudo apt-get install Docker
Ubuntu16.04 Installing Docker