Currently supported versions of Ubuntu:
- Ubuntu xenial 16.04 (LTS)
- Ubuntu Wily 15.10
- Ubuntu trusty 14.04 (LTS)
- Ubuntu precise 12.04 (LTS)
Prerequisites
Kernel version cannot be less than 3.10
uname -R3.11. 0--generic
If you previously used apt to install Docker, make sure that you update the APT source to the new Docker repository.
Update your apt sources
1. Log in with sudo permission or root user
2. Open a terminal window
3. Update package information to ensure APT works HTTPS and install CA certificate
sudo apt-sudoinstall Apt-transport-https ca-certificates
4. Add a new GPG key
sudo apt-key adv--keyserver HKP://p80.pool.sks-keyservers.net:80--recv-keys 58118e89f3a912897c070adbf76221572c52609d
5, edit the/etc/apt/sources.list.d/docker.list file, if it does not exist, create a
6. Delete all existing entries
7. Add a
14.04 (LTS) deb https: // Apt.dockerproject.org/repo Ubuntu-trusty Main
# on Ubuntu xenial 16.04 (LTS)
Deb Https://apt.dockerproject.org/repo ubuntu-xenial Main
8. Save and close the/etc/apt/sources.list.d/docker.list file
9. Update APT Package Index
sudo apt-get update
10. Empty the old repo (if present)
sudo apt-get purge lxc-docker
11. Verification Repository Effective
$ Apt-cache Policy Docker-engine
Prerequisites by Ubuntu Version
For Ubuntu 14.04, 15.10, 16.04, it is recommended to install the Linux-image-extra kernel Pack, Linux-image-extra package allows you to use AUFS storage driver.
1. Open a terminal window
2. Update Package Manager
sudo apt-get update
3, install the recommended package
sudo Install linux-image-extra-$ (uname -R)
4. Continue to install Docker
If it is Ubuntu 14.04 or 12.04, you need to install AppArmor
Install AppArmor
Install
Make sure the prerequisites are met, and then start installing Docker
1. User Login with sudo permission
2. Update APT Package Index
sudo apt-get update
3. Installing Docker
sudo Install Docker-engine
4. Start the Docker daemon
sudo service docker start
5. Verify that Docker is installed correctly
sudo Docker run Hello-world
This command downloads a test image and runs it inside the container, outputting a set of messages to the screen and exiting.
Optional configurationscreate a Docker group
The Docker daemon binds to the Unix socket, not the TCP port. By default, the Unix socket belongs to the root user, and other users can access it via the sudo command. As a result, the Docker daemon has been running as the root user.
To avoid the need for sudo every time you use the Docker command, you can create a Unix group named Docker to add users to this group. That way, when the Docker daemon starts, it gives the group read and write access to the Unix socket.
Warning: The Docker Group is equivalent to the root user, which has security implications for your system, please refer to the Docker Daemon Attack Surface documentation for details.
Create a docker group and add Users:
1. User Login with sudo permission
2. Create a Docker group
sudo groupadd Docker
3. Add users to the Docker group
sudo usermod-ag Docker $USER
4. Log off and re-login
5. Verify that you do not need sudo to execute Docker commands
$ Docker Run Hello-world
If the failure prompts the following similar information:
Cannot connect to the Docker daemon. Is ' Docker daemon ' running on this host?
Check to see if the DOCKER_HOST environment variable is set.
Adjust Memory and Swap accounting
When you run Docker, you may receive the following warning:
Warning:your kernel does not support Cgroup swap limit. Warning:your kernel does not the support swap limit capabilities. limitation discarded.
To avoid this type of information, you need to enable memory and swap accounting on your system.
When enabled, it increases memory overhead and performance degradation, and instant Docker is not running. Memory overhead increases by about 1%, and performance drops by about 10%.
1. User Login with sudo permission
2. Edit the/etc/default/grub file
3, set the value of Grub_cmdline_linux as follows
grub_cmdline_linux="cgroup_enable=memory swapaccount=1"
4. Save and close the file
5. Update GRUB
sudo update-grub
6. Restart the system
Enable UFW Forwarding
If you are using the UFW firewall, you need to do some additional configuration. Docker uses bridge to manage the container network, and by default UFW discards all forwarding traffic, so you need to configure the UFW forwarding policy.
Similarly, the default rule for UFW denies all inbound traffic. Remote connection Docker, the default port when TLS is enabled is 2376, when not enabled is 2375. Docker does not enable TLS by default, and communication is not encrypted when TLS is not enabled.
UFW Allow inbound connections at the time of the match:
1. User Login with sudo permission
2. Confirm that UFW is installed and enabled
sudo UFW status
3. Edit the/ETC/DEFAULT/UFW file
sudo NANO/ETC/DEFAULT/UFW
4. Set Default_forward_policy to:
default_forward_policy="ACCEPT"
5. Save and close the file
6. Reload UFW
sudo UFW reload
7. Allow inbound access to Docker ports
sudo 2375/tcp
Configure a DNS server for use by Docker
Ubuntu systems generally use 127.0.0.1 as the default nameserver, which is configured in/etc/resolv.conf.
This causes a warning when the container is started:
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 reason is that the Docker container cannot use the local DNS server, and the default is to use external DNS.
To avoid warning, you can specify a DNS server or disable DNSMASQ in NetworkManager, and disabling DNSMASQ can cause DNS resolution to slow down on some networks.
Ubuntu 15.10 and later is using SYSTEMD as the boot and service Manager, referring to control and configure Docker with SYSTEMD Documentation
Ubuntu 14.10 and the following versions of the configuration method:
1. User Login with sudo permission
2. Edit the/etc/default/docker file
sudo nano/etc/default/docker
3. Add a Setting
docker_opts="--dns 8.8.8.8"
You can also set multiple DNS servers
--dns 8.8.8.8--dns 192.168.1.1
4. Save and close the file
5. Restart the Docker daemon
sudo service docker restart
or by disabling the DNSMASQ method:
1. Edit the/etc/networkmanager/networkmanager.conf file
sudo nano/etc/networkmanager/networkmanager.conf
2, comment out DNS=DNSMASQ line:
Dns=dnsmasq
3. Save and close the file
4. Restart NetworkManager and Docker
sudo restart network-sudo restart Docker
Configure Docker to start on boot
The Ubuntu 15.04 version uses SYSTEMD as the boot and Service Manager, and the 14.10 version below uses upstart.
15.04 or later, configure Docker boot boot
sudo systemctl enable Docker
14.10 The following versions of the installation process will automatically configure the boot start
Upgrade Docker
To install the latest version of Docker using Apt-get:
sudo apt-get upgrade Docker-engine
Uninstallation
To uninstall a Docker package:
sudo apt-get purge docker-engine
To uninstall Docker and its dependent packages:
sudo apt-get autoremove--purge docker-engine
The appeal command does not remove images, containers, volumes, and user-created profiles, using the following command to delete all mirrors, containers, and volumes:
RM -rf/var/lib/docker
User-created profiles must be manually deleted.
Install Docker on Ubuntu