DEV Community

Ahmed Adawy
Ahmed Adawy

Posted on

4 Docker Commands I Use Almost Every Day (And You Probably Will Too)

When I first started using Docker, I kept searching for the same commands over and over again.

Eventually, I realized that I only needed a handful of commands for 90% of my daily work.

Here are the four Docker commands I use the most.


1. Build an Image

docker build -t myapp:v1 .
Enter fullscreen mode Exit fullscreen mode

This command creates a Docker image from your Dockerfile.

I always use version tags instead of latest because it makes deployments easier to track and roll back.


2. Run a Container

docker run -d -p 8080:8080 --name myapp_instance myapp:v1
Enter fullscreen mode Exit fullscreen mode

What this does:

  • Runs the container in the background
  • Maps port 8080 on your machine to the container
  • Gives the container a readable name

Instead of random container IDs, I can simply reference myapp_instance.


3. Monitor What's Happening

docker ps
Enter fullscreen mode Exit fullscreen mode

Shows all running containers.

Need to inspect logs?

docker logs -f myapp_instance
Enter fullscreen mode Exit fullscreen mode

The -f flag streams logs in real time, which is incredibly useful when debugging startup issues.


4. Stop and Remove Cleanly

docker stop myapp_instance && docker rm myapp_instance
Enter fullscreen mode Exit fullscreen mode

One command.

No leftover containers.

No unnecessary clutter.


A Small Habit That Saves Time

I almost never use anonymous containers during development.

Naming containers makes debugging, logging, restarting, and scripting much easier.

It seems like a tiny habit, but it saves a surprising amount of time over the long run.


Quick Reference

docker build -t myapp:v1 .
docker run -d -p 8080:8080 --name myapp_instance myapp:v1
docker ps
docker logs -f myapp_instance
docker stop myapp_instance && docker rm myapp_instance
Enter fullscreen mode Exit fullscreen mode

That's it.

You don't need to memorize dozens of Docker commands.

Master these four first, and you'll already handle most day-to-day Docker workflows with confidence.


If you found this useful, save it for later—you'll probably need these commands again.

Top comments (0)