After Part 1, where we were Running a single docker container explained step by step, we’re now in Part 2: We are running multiple containers side by side.
Again, make sure you installed “Docker Desktop” and you have the Docker Daemon running. Then open a PowerShell on Windows, a Terminal on Mac/Linux and follow along! This is fun.
Docker Run Video Walkthrough
You can also follow along in this video, if you prefer. You can also get this as a full Docker Video QuickStart Course
Step by Step Docker Run Tutorial
This shows the difference between containers and images. We will create two containers (linux1 and linux2) based on the same image (ubuntu)
docker run -it -d --rm --name linux1 ubuntu /bin/bash
This creates container “linux1”.
- -d starts the container as “detached”. Use “docker attach” to attach to it later on.
- — rm cleans up the container after stopping. The container will be removed, basically the same as “docker rm container_identifier” after stopping the container. So everything is kept tidy.
- — name will give the container a dedicated name, which makes it easier to address the container later on.
docker run -it -d --rm --name linux2 ubuntu /bin/bash
Creates container “linux2”
docker attach linux1
Attaches to container linux1
This lists the file system on linux1.
Creates a new directory on container linux1
shows that “mylinux1” was created
Now open a second PowerShell Window (or Terminal on a Mac) and run in the second PowerShell Window (CLI2):
CLI2: docker attach linux2
Attaches to container linux2
Shows that the directory of linux2 is different than linux1, although they are both from the same image “ubuntu”
- They are separated, they don’t share their file-system
- The bash process is isolated in the container
This will exit the bash and also remove the container because of the — rm command
CLI2: docker ps -a
Shows only one container which is running, the other one got removed
Exits the only running container linux1 and deletes the container
docker ps -a
Shows nothing anymore
In the next part you are going to apply Docker Volumes step by step.
Heads-Up: If you like this, then also check out the video course Understanding Docker and Docker-Compose — 100% Hands-On. It’s a 2.5h Quickstart into Docker. If you want more, then checkout my blog where I have tons of Beginner Tutorials about about Blockchain, Solidity, Ethereum, Docker and other Technical Topics.