Ech0 - 29 / 08 / 2020

Docker Installation

Here is a tutorial on how to install Docker on debian-based distros quickly:

Initial Setup

Right now i'm running a debian virtual machine using QEMU KVM virt-manager you can see my tutorial for that here. It is a default debian10 distribution with ssh server on it:

Installing Docker



In most cases you want to use one of these 2 commands:


curl -fsSL https://get.docker.com -o get-docker.sh 
sh get-docker.sh

or:


apt install docker.io

and once that's done we can verify that docker is installed by typing the following commands:


root@nowhere:/home/nothing# which docker && docker -v
/usr/bin/docker
Docker version 18.09.1, build 4c52b90

And that's it! We have been able to install docker on our debian machine.

Testing Docker



Now that's done we'll test if docker works by pulling in an application we find on docker hub, one of the most popular containers out there is nginx, so let's first pull it to our local machine and see if it works:


root@nowhere:/home/nothing# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
bf5952930446: Pull complete
cb9a6de05e5a: Pull complete
9513ea0afb93: Pull complete
b49ea07d2e93: Pull complete
a5e4a503d449: Pull complete
Digest: sha256:b0ad43f7ee5edbc0effbc14645ae7055e21bc1973aee5150745632a24a752661
Status: Downloaded newer image for nginx:latest

root@nowhere:/home/nothing# docker container run -d -p 8080:80 --name mynginx nginx
671bc01b6a1056e5804bbd92d1fbeace1a765e8b5e19df135c7e8c37f91c0a9c

root@nowhere:/home/nothing# docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
671bc01b6a10        nginx               "/docker-entrypoint.…"   22 seconds ago      Up 22 seconds       0.0.0.0:8080->80/tcp   mynginx

Here we pulled nginx's container image, and ran it redirecting it's port 80 to our machine's port 8080 so let's check it out:



root@nowhere:/home/nothing# ip a | grep inet
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 192.168.122.64/24 brd 192.168.122.255 scope global dynamic enp1s0
    inet6 fe80::5054:ff:fee0:b0fa/64 scope link
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
    inet6 fe80::42:2dff:fe19:e6b4/64 scope link
    inet6 fe80::34e2:53ff:fef1:5763/64 scope link

And there you have it! we have been able to run a docker container on debian. However when we restart the machine, the container isn't running when we get back into our system, so we need to make sure the running container image runs at startup, after reading the documentation we do the following:


root@nowhere:/home/nothing# docker container run -d --restart unless-stopped -p 8080:80 --name mynginx4 nginx
681d739d98119338bf56dcab0b1b49c75ea01f1d675815dcfd30f0cbd8c04571
root@nowhere:/home/nothing# docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
681d739d9811        nginx               "/docker-entrypoint.…"   4 seconds ago       Up 4 seconds        0.0.0.0:8080->80/tcp   mynginx4

We reboot the machine and see if our nginx container is still up:



And it is! That concludes our tutorial.

My Bunker

Some Address 67120,
Duttlenheim, France.

About Ech0

This cute theme was created to showcase your work in a simple way. Use it wisely.