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 With Options: docker run -d -p 8080:80 nginx -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 To see all containers (including stopped ones): docker ps -a docker images Shows all local Docker images. docker images docker exec Runs a command inside a running container. docker exec -it my_container bash -it: opens an interactive shell session inside the container docker logs Displays the logs of a container. docker logs my_container Use -f to follow the log output in real time: docker logs -f my_container docker build Builds a new image from a Dockerfile. docker build -t my_image . -t: tags the image with a name docker stop / docker start Stops or starts containers. docker stop my_container docker start my_container docker rm / docker rmi Removes containers or images. docker rm my_container docker rmi my_image -f: force removal if needed. docker-compose up Starts all services defined in a docker-compose.yml file. docker-compose up -d -d: runs services in the background docker volume Manages persistent volumes. docker volume ls docker volume create my_volume docker volume rm my_volume 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!

Apr 23, 2025 - 17:53
 0

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

With Options:

docker run -d -p 8080:80 nginx
  • -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

To see all containers (including stopped ones):

docker ps -a

docker images

Shows all local Docker images.

docker images

docker exec

Runs a command inside a running container.

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

docker logs

Displays the logs of a container.

docker logs my_container

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

docker logs -f my_container

docker build

Builds a new image from a Dockerfile.

docker build -t my_image .
  • -t: tags the image with a name

docker stop / docker start

Stops or starts containers.

docker stop my_container
docker start my_container

docker rm / docker rmi

Removes containers or images.

docker rm my_container
docker rmi my_image
  • -f: force removal if needed.

docker-compose up

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

docker-compose up -d
  • -d: runs services in the background

docker volume

Manages persistent volumes.

docker volume ls
docker volume create my_volume
docker volume rm my_volume

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!