Hello! If you’re a developer, you’ve probably heard the term ‘Docker’ at least once. It’s often called a magical tool that makes the phrase “It worked fine on my machine…” disappear. π
However, when you actually try to start, you might feel overwhelmed by the black terminal screen. So today, I’ve gathered and organized the essential commands that govern Docker’s core lifecycle, making them easy for anyone to follow. With this one article, you’ll be able to take your first step towards mastering Docker containers!

Step 1: Managing Existing Containers (View, Stop, Delete) π¦
First, let’s learn how to manage containers that are already running. Just like a computer’s task manager, Docker also has a function to view and manage running processes (containers).
β View List of Running Containers: docker ps
This command checks which containers are currently running on your server.
# Shows only actively running containers.
docker ps
If you want to see all containers, including stopped ones, add the -a option.
# Shows all containers, whether running or stopped.
docker ps -a
Through this command, you can quickly grasp important information such as the container’s ID, name, image in use, and ports.
π Stop a Running Container: docker stop
If you have a container you no longer need, you can safely stop it. Use the container’s ID or name, which you can find with the docker ps command.
# docker stop <container_ID_or_name>
docker stop a1b2c3d4e5f6
ποΈ Permanently Delete a Container: docker rm
stop only pauses a container; it doesn’t delete it completely. To fully remove an unnecessary container, you must use the rm command. Important: A running container cannot be deleted directly, so you must stop it first.
# docker rm <container_ID_or_name>
docker rm a1b2c3d4e5f6
π‘ Pro Tip: Want to stop and delete at once? Use the -f (force) option to directly delete a running container. docker rm -f
Step 2: Creating Your Own Blueprint (Building Docker Images) π οΈ
Now that you’ve cleaned up existing containers, it’s time to create a new image containing your own application.
- What is a Dockerfile? It’s a text file that sequentially records all the settings required to run your application (base OS, programs to install, source code copying, execution commands, etc.), essentially an image blueprint.
- What is an Image? It’s a package built based on this Dockerfile blueprint, containing everything needed to run the application.
The magic command to turn this blueprint into an image is docker build.
Bash
# cd /move-to-Dockerfile-path
# docker build -t <imagename:tag> <Dockerfilepath>
docker build -t my-web-app:1.0 .
Let’s look at each part of the command:
docker build: Means “Build an image with this blueprint!”-t my-web-app:1.0: The-toption is for tagging the image with a name and version (e.g.,my-web-appwith version1.0). Naming it this way makes it easy to find and use the image later..: Refers to the path where the Dockerfile is located..means ‘current directory’.
Step 3: Finally Run! (Deploying Containers to the World) π
Now, it’s time to take your well-built image and run it as a functional container! Let’s learn about the docker run command, which is the most important and has many options.
# docker run [options] <imagename:tag>
docker run -d --name my-server -p 8080:80 my-web-app:1.0
Wow, it might look long, but it’s incredibly convenient if you know just a few key options.
-d (--detach): Runs the container in the background. Without this option, the container would occupy your terminal, preventing you from doing other tasks. This is a must-have option for server applications!--name my-server: Assigns a name,my-server, to the container. Naming it makes it much easier to manage later, like withdocker stop my-server.-p 8080:80: This is the most important option for connecting ports. It means external (host) port:internal (container) port. The example above means “Forward requests coming to port 8080 on my computer to port 80 of the container!” Thanks to this, we can access the web server running inside the container viahttp://localhost:8080.my-web-app:1.0: Finally, specify the name of the image to run.
In Conclusion
Today, we’ve experienced all three core flows of Docker:
- Management (ps, stop, rm): Cleaning up existing containers.
- Build (build): Creating your own image.
- Run (run): Deploying your application to the world.
Even just getting familiar with these three command cycles will enable you to confidently handle most Docker tasks. Now, try turning your projects that only ran on your computer into Docker images to share with friends or easily deploy to a server!
Tags: Docker, Container, Virtualization, DevOps, Development, Server, Image Build, Docker Basics
Leave a Reply