Install Docker on Ubuntu/Debian

Config du dépôt

$ sudo apt update
$ sudo apt install \
        apt-transport-https \
        ca-certificates \
        curl \
        software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo add-apt-repository \
       "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
       $(lsb_release -cs) \
       stable"

Installer Docker CE

$ sudo apt update
$ sudo apt install docker-ce
Configurer le système pour ne pas avoir à sudo chaque cmd docker
groups
sudo usermod -aG docker $USER
Note
groups nous donne les groupes auxquel on appartient NOTE: $USER correspond à l’utilsateur courrant

Commandes utiles docker

docker ps
docker run -it ubuntu bash #lancer un container ubuntu dans le terminal
watch -n 1 docker ps # dans une autre session
ctrl-d #pour quitter la session ubuntu-docker
Note
On voit que le container s’est arrêté

Installer Portainer pour la GUI

$ sudo docker volume create portainer_data
$ sudo docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

Dockerize an SSH service

Build the image

$ mkdir docker-ssh-folder
$ cd docker-ssh-folder
$ nano Dockerfile

Here is your dockerfile

FROM ubuntu:latest

RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:YOURPASSWD' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Note
Change YOURPASSWD

Build the image using

$ docker build -t ubuntu_sshd .

Run a ubuntu_sshd container

$ docker run -d -P -p HOST_PORT:22 --name test_sshd ubuntu_sshd

Then connect to your container and create a user to ssh into it

$ docker exec -ti test_sshd bash
$ adduser USERNAME

Now you can connect to your machine like this:

$ ssh USERNAME@localhost -p HOST_PORT

To do some clean up

$ docker container stop test_sshd
$ docker container rm test_sshd
$ docker image rm ubuntu_sshd