Install docker on Ubuntu

Recommend to you##

Dcoker entry and practice series of articles

Ubuntu installation docker

docker currently supports the following ubuntu operating systems:

Note: Ubuntu Utopic 14.10 and 15.04 exist in Docker’s APT repository but are no longer officially supported.

limitation factor##

$ uname -r
3.11.0- 15- generic

Update apt source##

$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates
# Add secret key
$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80--recv-keys  58118E89F3A912897C070ADBF76221572C52609D

vi /etc/apt/sources.list.d/docker.list

Add the following entries to the file according to different operating systems

Save and exit

Update APT package index.

$ sudo apt-get update
Purge the old repo if it exists.

$ sudo apt-get purge lxc-docker
Verify that APT is pulling from the right repository.

$ sudo apt-cache policy docker-engine
From now on when you run apt-get upgrade, APT pulls from the newrepository.

Prerequisites by Ubuntu Version

$ sudo apt-get update
Install the recommended package.

$ sudo apt-get install linux-image-extra-$(uname -r)
Go ahead and install Docker.

If you are installing on Ubuntu 14.04 or 12.04, apparmor is required. You can install it using:
sudo apt-get install apparmor

Install Docker

$ sudo apt-get update
$ sudo apt-get install docker-engine
$ sudo service docker start
sudo apt-get install docker-engine=1.10.1-0~trusty

Optional##

This section contains optional procedures for configuring your Ubuntu to work better with Docker.

Create Docker User Group###

$ sudo usermod -aG docker <YOUR_USERNAME>

Adjust memory and swap space (swap accounting)

When we use Docker to run an image, we may see the following information prompt:

WARNING: Your kernel does not support cgroup swap limit. WARNING: Your
kernel does not support swap limit capabilities. Limitation discarded.

In order to prevent the above error messages from appearing, we need to enable memory and swap space in the system. We need to modify the system's GUN GRUB (GNU GRand Unified Bootloader) to enable memory and swap space. The opening method is as follows:

  1. Use a user with sudo privileges to log in to your Ubuntu.
  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 files
  5. Update GRUB
    $ sudo update-grub
  6. Restart your system.

Allow UFW port forwarding###

When you use UFW (simple firewall) on the host where docker is running. You need to do some additional configuration. Docker uses bridging to manage the network. By default, UFW filters all port forwarding policies. Therefore, when using docker with UFW enabled, you must set the UFW port forwarding strategy appropriately.
By default, UFW filters out all inbound rules. If other hosts can access your container. You need to allow all connections on Docker's default port (2375).
Set UFW to allow inbound rules for Docker ports:

  1. Use a user with sudo privileges to log in to your Ubuntu
  2. Verify the installation and activation status of UFW
    $ sudo ufw status
  3. Open and edit /etc/default/ufw file
    $ sudo nano /etc/default/ufw
  4. Set DEFAULT_FORWARD_POLICY as follows:
    DEFAULT_FORWARD_POLICY="ACCEPT"
  5. Save and close the file.
  6. Reload UFW to make the new rules take effect.
    $ sudo ufw reload
  7. Allow inbound rules for Docker ports
    $ sudo ufw allow 2375/tcp

Docker configuration DNS service###

Whether it is Ubuntu or the Ubuntu desktop multiplication version, when the system is running, it uses 127.0.0.1 in the /etc/resolv.conf configuration file as the nameserver. NetworkManager sets dnsmasq to use the real dns server connection, and sets the domain name service of /etc/resolv.conf to 127.0.0.1.
When using these configurations to run docker containers in a desktop environment, Docker users will see the following 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.88.8.4.4]

The warning is because the Docker container cannot use the local DNS service. Instead Docker uses a default external domain name server.
To avoid this warning, you can specify a DNS server for the Docker container. Or you can disable NetworkManager's dnsmasq. However, when dnsmasq is disabled, it may slow down the DNS resolution of some networks.
Specify a DNS server for Docker

  1. Use a user with sudo privileges to log in to your Ubuntu.
  2. Open and edit /etc/default/docker

$ sudo nano /etc/default/docker
3. Add settings

``` DOCKER_OPTS="--dns 8.8.8.8"```

Use 8.8.8.8 Replace as 192.168.1.1 local DNS server. You can specify multiple DNS servers, and multiple DNS servers are separated by spaces. For example

```- - dns 8.8.8.8 --dns 192.168.1.1```

 caveat:If the computer you are using needs to be connected to a different network,Be sure to choose a public DNS server.
  1. Save and close the file.
  2. Restart the Docker process
    $ sudo restart docker
    Or, as an alternative to the previous operation, disable dnsmasq in NetworkManager (this will slow down your network)
  3. Open and edit /etc/default/docker
    $ sudo nano /etc/NetworkManager/NetworkManager.conf
  4. Comment out dns = dsnmasq:
    dns=dnsmasq
  5. Save and close the file
  6. Restart NetworkManager and Docker
$ sudo restart network-manager 
$ sudo restart docker

Configure Docker to start on boot

Ubuntu uses systemd as its boot and service manager 15.04 onwards and upstart 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 configures upstart to start the docker daemon on boot

Update Docker (Upgrade Docker)

To install the latest version of Docker with apt-get:

$ sudo apt-get upgrade docker-engine

Uninstall Docker(Uninstallation)

# To uninstall the Docker package:

$ sudo apt-get purge docker-engine
# To uninstall the Docker package and dependencies that are no longer needed:

$ sudo apt-get autoremove --purge docker-engine
# The above commands will not remove images, containers, volumes, or 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.

Recommended Posts

Install docker on Ubuntu
Install Docker on ubuntu18.04
Install Docker on Ubuntu18
Docker practice (1): install Docker on Ubuntu 16.04
Install Docker on Ubuntu 18.04 offline
ubuntu18.04 install docker
docker install ubuntu
Docker ubuntu: install python-PIL-image environment on 14.04
Install Docker on Centos7
Install Redis on Ubuntu
Install R4 on ubuntu20
Install nvtop on Ubuntu 18.04
Install postgresql-10 on Ubuntu 18.04
Install nodejs10 on Ubuntu16
Install mysql on Ubuntu 14.04
Install Django on ubuntu
Install Pytorch+CUDA on Ubuntu 16.04
Install Python3 on Ubuntu 14.04
Install rJava on Ubuntu18
Install JDK10+ on Ubuntu
Install Python3 on Ubuntu 16.04
Install KDE on Ubuntu16.04.2
install Docker on centos6.5
Install Python3.7 on Ubuntu
Install flashplayer on Ubuntu
How to install Docker Compose on Ubuntu 18.04
Install docker on ubuntu and basic usage
Install ubuntu on virtual machine
Install QQ robot on Ubuntu 16.04
Install Python 3.7 on Ubuntu 18.04 LTS
Install Android Studio on Ubuntu
How to install and use Docker on Ubuntu 20.04
Install scrapy framework on ubuntu
Install docker transfer on Centos7
Install Mysql offline on Ubuntu
Install Oracle Java8 on Ubuntu
Install docker on Centos system
Install Odoo 11 stack on Ubuntu 16.04
Install Go locale on Ubuntu16
Install common software on Ubuntu 16.04
Install non-portable QQ on ubuntu
How to install and use Docker on Ubuntu 16.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
Install Tenda u12 driver on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
Install and configure MySQL on Ubuntu
Install Chef server workstation on Ubuntu 18.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
Install botan2 encryption library on ubuntu
How to install PostgreSQL on Ubuntu 16.04