Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code. – by opensource.com
First, update all existing packages list.
sudo apt update
Install prerequisites packages which supports “apt” use packages over HTTPS.
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add the GPG Key from the official Docker repository site to your system.
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
Add the Docker repository to APT sources.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian stretch stable"
Update the packages once again with the Docker packages.
sudo apt update
Execute the below command to make sure installing the docker from official docker repository instead of default one from your Linux Debian.
apt-cache policy docker-ce
You will get the below message in your console about the Docker.
docker-ce: Installed: (none) Candidate: 5:19.03.0~3-0~debian-stretch Version table: 5:19.03.0~3-0~debian-stretch 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 5:18.09.8~3-0~debian-stretch 500 500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
Now this is the time to install the Docker. Execute the below command to install Docker in your Linux Debian 9.
sudo apt install docker-ce
After docker installation, check the daemon started and the docker process is enabled to start on boot.
sudo systemctl status docker
You will get the below message on the console and showing that service is started and running.
docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2019-07-25 15:08:26 UTC; 52s ago Docs: https://docs.docker.com Main PID: 10170 (dockerd) CGroup: /system.slice/docker.service └─10170 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Jul 25 15:08:25 my-blog-vm dockerd: time="2019-07-25T15:08:25.843745232Z" level=warning msg="Your kernel does not support swap memory limit" Jul 25 15:08:25 my-blog-vm dockerd: time="2019-07-25T15:08:25.844505558Z" level=warning msg="Your kernel does not support cgroup rt period" Jul 25 15:08:25 my-blog-vm dockerd: time="2019-07-25T15:08:25.845028493Z" level=warning msg="Your kernel does not support cgroup rt runtime" Jul 25 15:08:25 my-blog-vm dockerd: time="2019-07-25T15:08:25.845611976Z" level=info msg="Loading containers: start." Jul 25 15:08:25 my-blog-vm dockerd: time="2019-07-25T15:08:25.922639398Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon Jul 25 15:08:25 my-blog-vm dockerd: time="2019-07-25T15:08:25.958337077Z" level=info msg="Loading containers: done." Jul 25 15:08:25 my-blog-vm dockerd: time="2019-07-25T15:08:25.984441997Z" level=info msg="Docker daemon" commit=aeac9490dc graphdriver(s)=overlay2 version=19.03.0 Jul 25 15:08:25 my-blog-vm dockerd: time="2019-07-25T15:08:25.985341692Z" level=info msg="Daemon has completed initialization" Jul 25 15:08:26 my-blog-vm systemd: Started Docker Application Container Engine. Jul 25 15:08:26 my-blog-vm dockerd: time="2019-07-25T15:08:26.024181113Z" level=info msg="API listen on /var/run/docker.sock"
Now execute the below commands to run Hello World in docker by login as root user. Otherwise, add the “sudo” before the docker commands.
docker run hello-world
You will get the following output on the console.
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: The Docker client contacted the Docker daemon. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/ …
Execute few more docker commands and play with it.
To view the list of docker running containers.
To view the list of docker images.
Docker has been installed successfully on the Linux Debian 9.