📝 Docker

Basic Docker Commands

0
Author
04e5cc8b-58ac-4bdc-bdee-661bbb
📅
Published
08.05.2026
⏱️
Reading time
1 min
👁️
Views
58
🌱
Level
Beginner

Working with Images

docker images                    # list downloaded images
docker pull nginx                # pull an image
docker rmi nginx                 # remove an image
docker image prune               # remove unused images

Running Containers

docker run hello-world           # run and stop
docker run -it ubuntu bash       # interactive mode
docker run -d nginx              # run in background (detached)
docker run -d -p 8080:80 nginx   # with port mapping
docker run -d --name my-nginx nginx  # with a name
docker run -d -e KEY=value nginx # with an environment variable
docker run --rm -it ubuntu bash  # remove after stop

Flags:
- -d — detached mode (background)
- -it — interactive terminal
- -p host:container — port mapping
- -e KEY=value — environment variable
- --name — custom name
- --rm — auto-remove on stop

Managing Containers

docker ps                        # running containers
docker ps -a                     # all, including stopped
docker stop my-nginx             # stop
docker start my-nginx            # start an existing container
docker restart my-nginx          # restart
docker rm my-nginx               # remove (must be stopped)
docker rm -f my-nginx            # force remove
docker container prune           # remove all stopped containers

Logs and Debugging

docker logs my-nginx             # all logs
docker logs -f my-nginx          # follow logs in real time
docker logs --tail 50 my-nginx   # last 50 lines

docker exec my-nginx ls /etc/nginx        # run a command
docker exec -it my-nginx bash             # get a shell inside
docker inspect my-nginx                   # full container info
docker stats                              # resource usage
docker stats --no-stream                  # resource snapshot

Cleanup

docker system prune              # remove all unused resources
docker system prune -a           # including images with no containers
docker system df                 # how much disk Docker is using

Lifecycle Cheat Sheet

docker pull   →  image downloaded
docker run    →  container created and started
docker stop   →  container stopped (data preserved)
docker start  →  container started again
docker rm     →  container removed
docker rmi    →  image removed

Useful Aliases

Add to ~/.zshrc or ~/.bashrc:

alias dps='docker ps'
alias dpsa='docker ps -a'
alias dlog='docker logs -f'
alias dex='docker exec -it'

Your reaction to the article

💬 Comments (0)

🔐 Sign in to leave a comment
🚪 Login
💭

No comments yet

Be the first to share your opinion about this article!

🔗 Similar

Similar articles

Continue learning with these materials

📝

Layers and Caching in Docker

Every instruction in a Dockerfile creates a layer — an intermediate image. Docker caches layers...

📅 08.05.2026 👁️ 61
📝

Docker Hub — Image Registry

Docker Hub is the public Docker image registry. Think of it as npm for Node.js...

📅 08.05.2026 👁️ 49
📝

Docker Compose: Multi-Container Applications

Docker Compose is a tool for running multiple related containers as a single application. The...

📅 08.05.2026 👁️ 49

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!