DEV Community

Cover image for 🐳 10 Essential Docker Commands Every Devs Should Know
Aleson França
Aleson França

Posted on

1

🐳 10 Essential Docker Commands Every Devs Should Know

If you're starting with Docker or just want to review the most useful commands, this guide is for you. These 10 commands will help you manage your containers and images with ease and confidence.


docker run

Creates and starts a new container from an image.

docker run hello-world
Enter fullscreen mode Exit fullscreen mode

With Options:

docker run -d -p 8080:80 nginx
Enter fullscreen mode Exit fullscreen mode
  • -p: maps a local port to the container port
  • -d: runs the container in the bg (detached mode)

docker ps

Lists running containers.

docker ps
Enter fullscreen mode Exit fullscreen mode

To see all containers (including stopped ones):

docker ps -a
Enter fullscreen mode Exit fullscreen mode

docker images

Shows all local Docker images.

docker images
Enter fullscreen mode Exit fullscreen mode

docker exec

Runs a command inside a running container.

docker exec -it my_container bash
Enter fullscreen mode Exit fullscreen mode
  • -it: opens an interactive shell session inside the container

docker logs

Displays the logs of a container.

docker logs my_container
Enter fullscreen mode Exit fullscreen mode

Use -f to follow the log output in real time:

docker logs -f my_container
Enter fullscreen mode Exit fullscreen mode

docker build

Builds a new image from a Dockerfile.

docker build -t my_image .
Enter fullscreen mode Exit fullscreen mode
  • -t: tags the image with a name

docker stop / docker start

Stops or starts containers.

docker stop my_container
docker start my_container
Enter fullscreen mode Exit fullscreen mode

docker rm / docker rmi

Removes containers or images.

docker rm my_container
docker rmi my_image
Enter fullscreen mode Exit fullscreen mode
  • -f: force removal if needed.

docker-compose up

Starts all services defined in a docker-compose.yml file.

docker-compose up -d
Enter fullscreen mode Exit fullscreen mode
  • -d: runs services in the background

docker volume

Manages persistent volumes.

docker volume ls
docker volume create my_volume
docker volume rm my_volume
Enter fullscreen mode Exit fullscreen mode

Conclusion

These are the most important Docker commands to help you get started and work more efficiently with containers. With practice, you’ll be using them naturally in your daily development tasks.

Do you use Docker often? What other commands do you find useful? Feel free to share them in the comments!

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)