util01@station66:~$ mkdir -p DOCKER/contssh
util01@station66:~$ cd DOCKER/contssh/
util01@station66:~/DOCKER/contssh$
Créer :
Dockerfile
Ajouter :
FROM ubuntu:latest
RUN apt update
RUN apt install openssh-server sudo -y
RUN useradd -rm -d /home/util01 -s /bin/bash -g root -G sudo -u 1000 util01
RUN usermod -aG sudo util01
RUN service ssh start
RUN echo 'util01:mot2passe' | chpasswd
EXPOSE 2222
CMD ["/usr/sbin/sshd","-D"]
util01@station66:~/DOCKER/contssh$ docker build -t container01 .
util01@station66:~/DOCKER/contssh$ docker run -p 2222:22 container01
util01@station66:~/DOCKER/contssh$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b59b57789d5 container01 "/usr/sbin/sshd -D" 28 seconds ago Up 27 seconds 2222/tcp, 0.0.0.0:2222->22/tcp, :::2222->22/tcp condescending_payne
util01@station66:~/DOCKER/contssh$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 3b59b57789d5
172.17.0.3
util01@station66:~/DOCKER/contssh$ ssh util01@172.17.0.3
The authenticity of host '172.17.0.3 (172.17.0.3)' can't be established.
ECDSA key fingerprint is SHA256:ATuP7g7rWrXpZ8i4C3zaFVaIWlN7qtMC0KylbcaOTRw.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/util01/.ssh/known_hosts).
util01@172.17.0.3's password:
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 4.15.0-99-generic x86_64)
...
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
util01@3b59b57789d5:~$
util01@station66:~/DOCKER/contssh$ docker stop 1eaf9f0d98bf
1eaf9f0d98bf