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 Docker on Debian 9 Stretch. This guide should also work on the previous version, i.e., Debian 8 (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:

READ: How to Install and Configure Docker Swarm on CentOS 7 / Ubuntu 16.04 / Fedora 25

READ: How to Setup Docker Private Registry on CentOS 7 / Ubuntu 16.04 / Fedora 25

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.

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值