1. 程式人生 > >Debian 9安裝docker ce

Debian 9安裝docker ce

How to Install Docker on Debian 9

Docker is a free and open-source containerization software that helps to deploy, run applications in a container. The containers are similar to a virtual machine but consume fewer resource, easy to manage and can run anywhere regardless of operating environment it is running in.

Docker uses cgroups

and namespace to allow the independent containers to run within a single Linux instance.

This guide will help you installing on Stretch. This guide should also work on the previous version, i.e., (Jessie)

Note: Docker needs a 64-bit version of Debian OS and Kernel version should be atleast 3.10.

Docker Editions:

Docker is now available in two editions, namely.

  • Community Edition (CE)
  • Enterprise Edition (EE)

Here, we will install Docker Comunity Edition (CE) from Docker repository.

Prerequisites:

Uninstall older versions of Docker called “docker” or “docker-engine” along with associated dependencies. If your system does not have a Docker package, skip the below step.

sudo apt-get -y remove docker docker-engine docker.io

Contents such as volumes, images, and networks under /var/lib/docker/ directory are preserved.

Setup Docker Repository:

Install below packages to have “apt” get a support of https method.

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates wget software-properties-common

Add the GPG key for Docker repository on your system.

wget https://download.docker.com/linux/debian/gpg 
sudo apt-key add gpg

Add the official Docker repository to the system by running below command in the terminal.

echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list.d/docker.list

Update the apt database.

sudo apt-get update

Make sure you are installing Docker from the official repository, not from the default Debian repository.

sudo apt-cache policy docker-ce

You should see the output like below with the Docker repository details.

docker-ce:
  Installed: (none)
  Candidate: 17.06.0~ce-0~debian
  Version table:
     17.06.0~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.03.2~ce-0~debian-stretch 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.03.1~ce-0~debian-stretch 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.03.0~ce-0~debian-stretch 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages

Install Docker:

Install Docker using the “apt-get” command.

sudo apt-get -y install docker-ce

Control Docker service:

To start Docker, run:

sudo systemctl start docker

To stop Docker service, run:

sudo systemctl stop docker

To restart Docker service, run:

sudo systemctl restart docker

To check the status of Docker service, run:

sudo systemctl status docker

To enable Docker service to autostart on system boot, run:

sudo systemctl enable docker

Verify Docker Installation:

To test the Docker installation, we will run “hello-world” container.

sudo docker run hello-world

Below output confirms that we have correctly installed Docker on Debian OS.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pull complete 
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Interested Topics:

Allow Non-root user to run Docker:

By default, to run Docker commands, the user should have root privileges or equivalent privileges via sudo. Sometimes we may need to allow non-root users to run Docker containers, so follow the below steps to allow them to run containers.

Create a group “docker“, if it does not exist.

sudo groupadd docker

Add your user to docker group, replace “raj” with your user name.

sudo useradd raj

Add a user to docker group.

sudo usermod -aG docker raj

Log out and log back in.

You should now be able to run Docker commands without prefixing sudo.