Docker Run Tutorial for absolute Beginners: Run a single docker container explained step by step
From the series: Getting Started with Docker for Developers Hands-On Examples — Part 1
Are you disappointed by the Docker Getting-Started docs? You couldn’t find anything suitable on YouTube? You want real hands-on? Then get started reading this!
Running a single docker container explained step by step
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.
You can also follow along in this video, if you prefer:
Enter this into the command line:
docker run -it ubuntu /bin/bash
What happens here?
- the command runs the container and attaches to stdin, the standard input, where the /bin/bash process is opened
flags “-it”: interactive flag, TTY flag (gives you a terminal)
ls
Shows the file system from linux. It’s inside the container.
Now open a second PowerShell (or Terminal) and type in
docker ps
This lists the currently running container
CLI1: exit
- On CLI1 to exit the container and the linux file system again
CLI2: docker ps
- Lists the currently running containers, which is empty
CLI2: docker ps -a
- Lists all containers, the running ones and the empty ones
CLI1: docker start container_identifier
- We can restart a container that was previously running
CLI2: docker ps
- The container comes up as running again.
- Mind: Creation date != running date
CLI1: docker attach container_identifier
- We can re-attach to the container
CLI2: docker stop container_identifier
- It will stop the running container
- It will automatically kick you out
docker ps
- The container is not running anymore, hence not listed here
docker ps -a
- The container is still in our system, but stopped
docker rm container_identifier
- Clean up: Remove the container
docker ps -a
- And the list is empty again, our container is gone
That’s it for this article. In the next part we are going to run multiple docker containers from the command line 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 blog regularly about Blockchain, Solidity, Ethereum, Docker and other Technical Topics