Distribution de travail : Lubuntu 22.04
Objectif :
Connexion ssh entre des conteneurs Docker
util01@station40:~$ mkdir -p DOCKER/conteneur01
util01@station40:~$ mkdir -p DOCKER/conteneur02
Créer :
~/DOCKER/conteneur01/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"]
Créer :
~/DOCKER/conteneur01/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@station40:~$ cd DOCKER/conteneur01
util01@station40:~/DOCKER/conteneur01$
util01@station40:~/DOCKER/conteneur01$ docker build -t conteneur01 .
Sending build context to Docker daemon 2.048kB
Step 1/9 : FROM ubuntu:latest
---> 6b7dfa7e8fdb
Step 2/9 : RUN apt update
---> Using cache
---> 292c8679888d
Step 3/9 : RUN apt install openssh-server sudo -y
---> Using cache
---> f1d6dd971146
Step 4/9 : RUN useradd -rm -d /home/util01 -s /bin/bash -g root -G sudo -u 1000 util01
---> Using cache
---> aeb994375acc
Step 5/9 : RUN usermod -aG sudo util01
---> Using cache
---> 3516add6acbf
Step 6/9 : RUN service ssh start
---> Using cache
---> 26dc09557c81
Step 7/9 : RUN echo 'util01:mot2passe' | chpasswd
---> Using cache
---> 35ef15a29196
Step 8/9 : EXPOSE 2222
---> Using cache
---> b42af2474caa
Step 9/9 : CMD ["/usr/sbin/sshd","-D"]
---> Using cache
---> 3a29251c2b91
Successfully built 3a29251c2b91
Successfully tagged conteneur01:latest
util01@station40:~/DOCKER/conteneur01$
util01@station40:~/DOCKER/conteneur01$ docker run -p 2222:22 conteneur01
util01@station40:~$ cd DOCKER/conteneur02
util01@station40:~/DOCKER/conteneur02$ docker build -t conteneur02 .
...
Successfully built 3a29251c2b91
Successfully tagged conteneur02:latest
util01@station40:~/DOCKER/conteneur02$
util01@station40:~/DOCKER/conteneur02$ docker run -p 2223:22 conteneur02
util01@station40:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4f3e8b394e33 conteneur02 "/usr/sbin/sshd -D" 25 seconds ago Up 23 seconds 2222/tcp, 0.0.0.0:2223->22/tcp, :::2223->22/tcp admiring_heisenberg
455faee74bc4 conteneur01 "/usr/sbin/sshd -D" 2 minutes ago Up 2 minutes 2222/tcp, 0.0.0.0:2222->22/tcp, :::2222->22/tcp exciting_chaum
util01@station40:~$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 4f3e8b394e33
172.17.0.3
util01@station40:~$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 455faee74bc4
172.17.0.2
util01@station40:~$ ssh util01@172.17.0.2
util01@172.17.0.2's password:
...
util01@455faee74bc4:~$
util01@455faee74bc4:~$ ssh 172.17.0.3
util01@172.17.0.3's password:
...
util01@4f3e8b394e33:~$
util01@455faee74bc4:~$ docker stop 4f3e8b394e33
util01@455faee74bc4:~$ docker stop 455faee74bc4