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:

Image for post
Image for post
Showing a linux file system inside a Windows PowerShell. Screenshot of “docker run -it ubuntu /bin/bash” and then “ls”

What happens here?

  1. 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)

Shows the file system from linux. It’s inside the container.

Now open a second PowerShell (or Terminal) and type in

Image for post
Image for post
Showing two PowerShell windows. One with a running ubuntu container, the other one outputting “docker ps”.

This lists the currently running container

  • On CLI1 to exit the container and the linux file system again
  • Lists the currently running containers, which is empty
Image for post
Image for post
Two Powershell windows. In the upper one I typed exit, in the lower one “docker ps” and it outputs an empty list of running containers.
  • Lists all containers, the running ones and the empty ones
Image for post
Image for post
  • We can restart a container that was previously running
Image for post
Image for post
I restarted the container with ID “c83ff57…” by typing “docker start c8”
  • The container comes up as running again.
  • Mind: Creation date != running date
Image for post
Image for post
Docker ps is listing the container as “Up” again
  • We can re-attach to the container
Image for post
Image for post
I am re-attaching to the running container
  • It will stop the running container
  • It will automatically kick you out
Image for post
Image for post
Entering “docker stop c8” in the lower powershell window automatically triggers an “exit” in the first one.
  • The container is not running anymore, hence not listed here
  • The container is still in our system, but stopped
  • Clean up: Remove the container
  • And the list is empty again, our container is gone
Image for post
Image for post
Listing container, cleaning up, and listing an empty list

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store