๐Ÿ“ Docker

Basic Docker Commands

P
Author
PyLand Team
๐Ÿ“…
Published
08.05.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
316
๐ŸŒฑ
Level
Beginner

Covered topics: Working with Images, Running Containers, Managing Containers, Logs and Debugging.

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

๐Ÿ“

Multi-stage Builds: Shrinking Your Docker Image

A large image means slow downloads, more disk usage, and a bigger attack surface. Multi-stage...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 318
๐Ÿ“

Docker Compose: Advanced Features

A basic docker-compose.yml is just the starting point. Production workloads need healthchecks, profiles, override files,...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 304
๐Ÿ“

Docker Networking: How Containers Communicate

Containers are isolated, but they often need to talk to each other and to the...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 303
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Docker: From Chaos to Containers Open course curriculum