This is a basic networking with docker containers
- This pulls the ubuntu image from DockerHub
docker run ubuntu
- This lists the docker images present locally
docker images
- (Container 1) - This runs the
ubuntu image
interactivelydocker run -it ubuntu bash
- (In another tab) - This checks the
Process Status
of the images, in order to see running images, you can add-a
docker ps
- (Container 2) - This runs the
ubuntu image
interactivelydocker run -it ubuntu bash
- (container 1) - This installs
sudo
apt install sudo -y
- (container 2) - This installs
sudo
apt install sudo -y
- (both) - This installs
openssh-server
forssh
connectionapt install openssh-server -y
- (both) - This checks
ssh
statusservice ssh status
- (both) - This
starts
ssh
service ssh start
- (both) - This checks
ssh
status to verify if it has started successfullyservice ssh status
- (both) - This installs
iproute2
so that we can get theip
of the container forssh
apt install iproute2 -y
- (both) - This installs
vim
for creating a file. Used to create thePublice Key
apt install vim -y
- (both) - This generates new
ssh
keys, bothprivate
andpublic
ssh-keygen
- (both) - This changes directory to the
.ssh
folder where the keys are storedcd /root/.ssh
- (container 1) and copy the public key - This shows the
Public Key
cat id_ed25519.pub
- (container 2) and past container 1's pub key - This creates the
authorized_keys
file. UseESC
andwq
to save the file.vim authorized_keys
- (container 2) and copy the ip - This shows the
ip
of the containerip addr
- (enter container 2 hostname and ip) or
ssh [email protected]
- Thisssh
into the container 2