{"id":27243,"date":"2026-01-15T14:26:34","date_gmt":"2026-01-15T13:26:34","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=27243"},"modified":"2026-01-19T11:19:32","modified_gmt":"2026-01-19T10:19:32","slug":"docker-commands-guide-for-developers","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/docker-commands-guide-for-developers\/","title":{"rendered":"Master Docker Commands for Container Management"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN.webp\" alt=\"Master Docker Commands for Container Management\" class=\"wp-image-27492\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN.webp 1200w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN-600x315.webp 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN-768x403.webp 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>Docker commands. You&#8217;ll need them. Every single day. The problem isn&#8217;t learning Docker. The problem is remembering which command does what when you&#8217;re three deploys deep and your production environment is burning. This guide breaks down the commands you&#8217;ll actually use, organized by what they do instead of alphabetically because that&#8217;s how your brain works under pressure.<\/p>\n\n\n\n<p>Commands fall into multiple categories: build &amp; manage images, clean up the mess, start and stop containers, check what&#8217;s running. Also configure containers, push to registries, orchestrate services, set up networks. Let&#8217;s get into it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-docker-build-commands\">Docker Build Commands<\/h2>\n\n\n\n<p>The docker build command turns your Dockerfile into an image. That&#8217;s it. Everything else is just options.<\/p>\n\n\n\n<p>Build from your current directory with <code>docker build<\/code>. Want to tag it so you can find it later? Add <code>-t imagename\/tag<\/code>. The tag isn&#8217;t optional if you plan to push to a registry.<\/p>\n\n\n\n<p>You can build from remote sources too. Point at a Git repo with <code>docker build https:\/\/github.com\/user\/repo.git#branch:folder<\/code>. Or grab a tar archive from your server with <code>docker build https:\/\/yourserver\/file.tar.gz<\/code>.<\/p>\n\n\n\n<p>Need to skip the cache? Use <code>--no-cache<\/code>. Pass build arguments with <code>--build-arg KEY=value<\/code>. These show up in your Dockerfile as ARG variables.<\/p>\n\n\n\n<p>The build process reads your Dockerfile line by line. Each instruction creates a layer. Layers get cached. That&#8217;s why your first build takes forever and subsequent builds finish in seconds. Unless you change something near the top of the Dockerfile. Then everything below that line rebuilds.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-docker-prune-and-cleanup-commands\">Docker Prune and Cleanup Commands<\/h2>\n\n\n\n<p>Docker fills your disk. Fast. Dangling images, stopped containers, unused volumes. They pile up.<\/p>\n\n\n\n<p>Run <code>docker system prune<\/code> to clear stopped containers, unused networks, dangling images, and build cache. Add <code>-a<\/code> to remove all unused images, not just dangling ones. This frees up gigabytes.<\/p>\n\n\n\n<p>For targeted cleanup, use <code>docker image prune<\/code> to delete untagged images. Clear volumes with <code>docker volume rm $(docker volume ls -f dangling=true -q)<\/code>. Remove specific images with <code>docker image rm imagename<\/code>.<\/p>\n\n\n\n<p>Want to nuke everything? Stop all running containers with <code>docker kill $(docker ps -q)<\/code>, then remove them with <code>docker rm $(docker ps -a -q)<\/code>. Don&#8217;t do this in production.<\/p>\n\n\n\n<p>Schedule prune commands in your deployment pipeline. Your DevOps team will thank you when they&#8217;re not hunting down disk space at 2 AM.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-managing-containers-start-stop-and-restart\">Managing Containers: Start, Stop, and Restart<\/h2>\n\n\n\n<p>Container lifecycle management. Start, stop, pause, restart. These commands control what&#8217;s running.<\/p>\n\n\n\n<p>Use <code>docker start containername<\/code> to fire up a stopped container. Stop it with <code>docker stop containername<\/code>. Restart with <code>docker restart containername<\/code>. Simple.<\/p>\n\n\n\n<p>Need to freeze a container temporarily? <code>docker pause containername<\/code> suspends all processes. Resume with <code>docker unpause containername<\/code>. The container&#8217;s state persists in memory.<\/p>\n\n\n\n<p>Stopping all containers at once requires a command chain. <code>docker stop $(docker ps -q)<\/code> stops everything currently running. The <code>-q<\/code> flag outputs only container IDs.<\/p>\n\n\n\n<p>Set restart policies when you launch containers. Use <code>--restart=always<\/code> for services that should survive system reboots. Or <code>--restart=on-failure<\/code> to restart only after crashes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-docker-logs-and-container-inspection\">Docker Logs and Container Inspection<\/h2>\n\n\n\n<p>Something broke. You need logs.<\/p>\n\n\n\n<p>Run <code>docker logs containername<\/code> to dump everything the container wrote to stdout and stderr. Add <code>-f<\/code> to follow logs in real-time. Use <code>--tail 100<\/code> to see just the last 100 lines.<\/p>\n\n\n\n<p>List running containers with <code>docker ps<\/code>. See everything, including stopped containers, with <code>docker ps -a<\/code>. The output shows container IDs, images, commands, status, and ports.<\/p>\n\n\n\n<p>Dig deeper with <code>docker inspect containername<\/code>. This dumps a JSON blob containing every detail: network settings, mounts, environment variables, resource limits. Pipe it to <code>grep <\/code>or <code>jq <\/code>to find what you need.<\/p>\n\n\n\n<p>Check resource usage with <code>docker stats<\/code>. It shows CPU percentage, memory usage, network I\/O, and block I\/O for each running container. Watch it stream live or capture a snapshot.<\/p>\n\n\n\n<p>See what changed in a container&#8217;s filesystem? <code>docker diff containername<\/code> lists added, deleted, and modified files. Useful for debugging containers that modify their own filesystems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-docker-images-management\">Docker Images Management<\/h2>\n\n\n\n<p>Images are templates. Containers are running instances. Managing images means keeping your local repository clean and tagged correctly.<\/p>\n\n\n\n<p>List all images with <code>docker images<\/code> or <code>docker image ls<\/code>. You&#8217;ll see repository names, tags, image IDs, creation dates, and sizes. Filter by name with <code>docker images imagename<\/code>.<\/p>\n\n\n\n<p>Tag images with <code>docker tag source target<\/code>. This creates a new reference to the same image. Common pattern: <code>docker tag myapp:latest myapp:v1.2.3<\/code>. Now you&#8217;ve got a version-specific tag and a latest tag pointing to the same image.<\/p>\n\n\n\n<p>Remove images with <code>docker image rm imagename<\/code> or <code>docker rmi imagename<\/code>. Delete multiple images by listing them: <code>docker rmi image1 image2 image3<\/code>.<\/p>\n\n\n\n<p>Check image history with <code>docker history imagename<\/code>. Each line shows a layer: the command that created it, when it was created, and how much disk space it uses. Bloated images? This shows you where.<\/p>\n\n\n\n<p>Prune unused images with <code>docker image prune<\/code>. Add <code>-a<\/code> to remove all images not referenced by any container. This isn&#8217;t reversible, so don&#8217;t get trigger-happy on your build server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-docker-run-command-options\">Docker Run Command Options<\/h2>\n\n\n\n<p>The docker run command creates and starts a container from an image. One command, dozens of flags.<\/p>\n\n\n\n<p>Basic syntax: <code>docker run imagename<\/code>. This runs the container in the foreground and blocks your terminal. Add <code>-d<\/code> to detach and run it in the background.<\/p>\n\n\n\n<p>Name your container with <code>--name containername<\/code>. Otherwise Docker generates random names like &#8216;quirky_tesla&#8217; that you&#8217;ll never remember. Map ports with <code>-p hostport:containerport<\/code>. Example: <code>-p 8080:80<\/code> maps container port 80 to host port 8080.<\/p>\n\n\n\n<p>Set environment variables with <code>-e KEY=value<\/code>. Mount volumes using <code>-v \/host\/path:\/container\/path<\/code>. Make the container filesystem read-only with <code>--read-only<\/code> for security.<\/p>\n\n\n\n<p>Auto-remove containers when they stop with <code>--rm<\/code>. Perfect for one-off tasks. Connect to specific networks using <code>--network networkname<\/code>. Set resource limits with <code>--memory<\/code> and <code>--cpus<\/code>.<\/p>\n\n\n\n<p>Interactive mode requires two flags: <code>-i<\/code> keeps stdin open and <code>-t<\/code> allocates a pseudo-TTY. Combine them as <code>-it<\/code> for shell access: <code>docker run -it ubuntu bash<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-docker-hub-and-registry-commands\">Docker Hub and Registry Commands<\/h2>\n\n\n\n<p>Docker Hub hosts millions of images. Your private registry might host yours. Either way, you need to pull, push, and authenticate.<\/p>\n\n\n\n<p>Log in with <code>docker login<\/code>. It prompts for username and password. For automated systems, pass credentials via stdin or use access tokens. Log out with <code>docker logout<\/code>.<\/p>\n\n\n\n<p>Pull images from Docker Hub with <code>docker pull imagename<\/code>. Specify tags like <code>docker pull nginx:1.21<\/code>. Without a tag, it defaults to latest. That&#8217;s often not what you want in production.<\/p>\n\n\n\n<p>Push images with <code>docker push username\/imagename:tag<\/code>. The image name must include your Docker Hub username or your registry URL. Tag it correctly before pushing or it&#8217;ll fail.<\/p>\n\n\n\n<p>Search Docker Hub from the command line using <code>docker search searchterm<\/code>. It returns official images, automated builds, and star counts. The web interface gives you more details though.<\/p>\n\n\n\n<p>For private registries, prefix image names with the registry URL: <code>registry.example.com\/imagename<\/code>. Login, pull, and push work the same way. Just point at a different registry.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-docker-swarm-service-management\">Docker Swarm Service Management<\/h2>\n\n\n\n<p>Docker Swarm orchestrates containers across multiple hosts. Services define how your containers should run in the swarm.<\/p>\n\n\n\n<p>List services with <code>docker service ls<\/code>. This shows service names, modes, replicas, images, and ports. For detailed info about a specific service, run <code>docker service ps servicename<\/code>.<\/p>\n\n\n\n<p>Create a service with <code>docker service create<\/code>. Example: <code>docker service create --name web --replicas 3 -p 80:80 nginx<\/code>. This deploys three nginx replicas across your swarm.<\/p>\n\n\n\n<p>Scale services up or down with <code>docker service scale servicename=5<\/code>. Swarm handles distributing the replicas. Update running services using <code>docker service update<\/code> with flags like <code>--image<\/code> for rolling updates.<\/p>\n\n\n\n<p>Check service logs with <code>docker service logs servicename<\/code>. This aggregates logs from all replicas. Deploy entire stacks using <code>docker stack deploy<\/code> with a compose file.<\/p>\n\n\n\n<p>Kubernetes won the orchestration war. But Swarm&#8217;s still simpler for smaller deployments. No learning curve. Just works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-docker-network-configuration\">Docker Network Configuration<\/h2>\n\n\n\n<p>Containers need to talk to each other and the outside world. Networks make that happen.<\/p>\n\n\n\n<p>List networks with <code>docker network ls<\/code>. You&#8217;ll see bridge, host, and none by default. Create custom networks using <code>docker network create networkname<\/code>. Specify drivers with <code>--driver bridge<\/code> or <code>--driver overlay<\/code> for swarm.<\/p>\n\n\n\n<p>Connect running containers to networks with <code>docker network connect networkname containername<\/code>. Disconnect with <code>docker network disconnect<\/code>. Containers can belong to multiple networks.<\/p>\n\n\n\n<p>The bridge network is default. Containers on the same bridge network can reach each other by name. Host network mode gives containers direct access to the host&#8217;s network stack. Use <code>--network<\/code> <code>host <\/code>when launching containers that need maximum network performance.<\/p>\n\n\n\n<p>Inspect network details with <code>docker network inspect networkname<\/code>. This shows connected containers, IP addresses, subnet configuration, and gateway settings. Remove unused networks with <code>docker network rm networkname<\/code>.<\/p>\n\n\n\n<p>Custom networks give you DNS resolution between containers. That&#8217;s why you create them instead of using the default bridge. Name resolution beats hardcoding IP addresses.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-docker-tutorial-and-best-practices\">Docker Tutorial and Best Practices<\/h2>\n\n\n\n<p>Commands are one thing. Using them correctly is another.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Start with the basics. Install Docker. Run <code>docker run hello-world<\/code>. If that works, you&#8217;re set. Build a simple Docker file. Create an image. Run a container. Break things. Fix them.<\/li>\n\n\n\n<li>Keep images small. Each layer adds size. Combine RUN commands. Clean up package caches in the same layer where you install them. Use multi-stage builds to separate build dependencies from runtime dependencies.<\/li>\n\n\n\n<li>Don&#8217;t run containers as root. Create a user in your Dockerfile with <code>RUN useradd<\/code>. Switch to it with <code>USER username<\/code>. Security matters even in containers.<\/li>\n\n\n\n<li>Tag your images properly. Use semantic versioning. Never rely on latest in production. Pin exact versions in your deployment configs. When an image updates and breaks your app, you&#8217;ll understand why.<\/li>\n\n\n\n<li>Monitor resource usage. Set memory limits with <code>--memory<\/code>. Cap CPU with <code>--cpus<\/code>. A container consuming all available resources takes down the entire host.<\/li>\n\n\n\n<li>Use health checks. Add <code>HEALTHCHECK <\/code>instructions to your Dockerfile. Docker can then automatically restart unhealthy containers. Better than waiting for your monitoring system to page you.<\/li>\n\n\n\n<li>Store secrets properly. Don&#8217;t bake them into images. Don&#8217;t pass them as environment variables that show up in <code>docker inspect<\/code>. Use Docker secrets for swarm or external secret management tools.<\/li>\n<\/ul>\n\n\n\n<p>The commands in this guide cover 90% of daily Docker work. The other 10%? That&#8217;s where you read the docs, search GitHub issues, and piece together solutions from Stack Overflow. Welcome to containerization!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker commands. You&#8217;ll need them. Every single day. The problem isn&#8217;t learning Docker. The problem is remembering which command does what when you&#8217;re three deploys deep and your production environment is burning. This guide breaks down the commands you&#8217;ll actually use, organized by what they do instead of alphabetically because that&#8217;s how your brain works [&hellip;]<\/p>\n","protected":false},"author":44,"featured_media":27492,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"ppma_author":[3402],"class_list":["post-27243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"uagb_featured_image_src":{"full":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN.webp",1200,630,false],"thumbnail":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN-150x150.webp",150,150,true],"medium":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN-600x315.webp",600,315,true],"medium_large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN-768x403.webp",768,403,true],"large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN.webp",1200,630,false],"1536x1536":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN.webp",1200,630,false],"2048x2048":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/01\/blog-head_guide-docker-commands-for-container-management_EN.webp",1200,630,false]},"uagb_author_info":{"display_name":"Milan Ivanovic","author_link":"https:\/\/contabo.com\/blog\/author\/milan\/"},"uagb_comment_info":0,"uagb_excerpt":"Docker commands. You&#8217;ll need them. Every single day. The problem isn&#8217;t learning Docker. The problem is remembering which command does what when you&#8217;re three deploys deep and your production environment is burning. This guide breaks down the commands you&#8217;ll actually use, organized by what they do instead of alphabetically because that&#8217;s how your brain works&hellip;","authors":[{"term_id":3402,"user_id":0,"is_guest":1,"slug":"contabro","display_name":"ContaBro","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/27243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=27243"}],"version-history":[{"count":6,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/27243\/revisions"}],"predecessor-version":[{"id":27546,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/27243\/revisions\/27546"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media\/27492"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=27243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=27243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=27243"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=27243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}