Logo

dev-resources.site

for different kinds of informations.

Docker Basics

Published at
1/9/2025
Categories
docker
container
linux
beginners
Author
nerdflash28
Categories
4 categories in total
docker
open
container
open
linux
open
beginners
open
Author
11 person written this
nerdflash28
open
Docker Basics

Table of Contents


Docker Basics

  • To know currently Running docker version
docker --version
Enter fullscreen mode Exit fullscreen mode
  • To get detailed information about docker installation
docker info
Enter fullscreen mode Exit fullscreen mode
  • to get help with docker use
docker help
Enter fullscreen mode Exit fullscreen mode

Working with Containers

  • to run a docker container
# docker run [options] image-name [command] [args]
# ex.
docker run nginx
# this will run container in detached mode
docker run -d nginx 
Enter fullscreen mode Exit fullscreen mode
  • to list running containers
docker ps 
Enter fullscreen mode Exit fullscreen mode
  • to list all the containers running or stopped
docker ps -a
Enter fullscreen mode Exit fullscreen mode
  • to stop a running stop
# docker stop [container_id/name]
docker stop nginx
Enter fullscreen mode Exit fullscreen mode
  • to start a stopped container
# docker start [container_id/name]
docker start nginx
Enter fullscreen mode Exit fullscreen mode
  • to restart a container
# docker restart [container_id/name]
docker restart nginx
Enter fullscreen mode Exit fullscreen mode
  • to remove a stopped container
# docker rm [container_id/name]
docker rm nginx
Enter fullscreen mode Exit fullscreen mode
  • to check logs of a container
# docker logs [container_id/name]
docker logs nginx
Enter fullscreen mode Exit fullscreen mode
  • to execute a command in a running container
docker exec -it [container_id] <command>
Enter fullscreen mode Exit fullscreen mode
  • to get detailed information about a container
docker inspect [container_id]
Enter fullscreen mode Exit fullscreen mode
  • to get real-time usage stats of a running container
docker stats
Enter fullscreen mode Exit fullscreen mode

Docker images

  • to list all the docker images
docker images
Enter fullscreen mode Exit fullscreen mode
  • to download an image from docker hub
# docker pull [image_name]
docker pull nginx
Enter fullscreen mode Exit fullscreen mode
  • to push a docker image to a registry
docker push [image_name]
Enter fullscreen mode Exit fullscreen mode
  • to export docker image to a tar file we use
docker save -o <file>.tar [image_name]
Enter fullscreen mode Exit fullscreen mode
  • to import docker image from tar file
docker load -i <file>.tar 
Enter fullscreen mode Exit fullscreen mode
  • to build an image from a docker file
# docker build -t [IMAGE_NAME:TAG]
docker build -t [image_name]
Enter fullscreen mode Exit fullscreen mode
  • to remove an docker image
# docker rmi [IMAGE_NAME:TAG
docker rmi nignx
Enter fullscreen mode Exit fullscreen mode

Docker volume

  • to create a docker volumes
# docker volume create [VOLUME_NAME]
docker volume create [VOLUME_NAME]
Enter fullscreen mode Exit fullscreen mode
  • to list all the volumes
docker volume ls
Enter fullscreen mode Exit fullscreen mode
  • to remove a volume
docker volume rm [VOLUME_NAME]
Enter fullscreen mode Exit fullscreen mode
  • to mount a volume to a container
docker run -v <volume>:/path/in/container [image_name]
Enter fullscreen mode Exit fullscreen mode

Docker networking

  • to list all the docker networks
docker network ls
Enter fullscreen mode Exit fullscreen mode
  • to create docker network
docker network create [NETWORK_NAME]
Enter fullscreen mode Exit fullscreen mode
  • to connect a container to a specific docker network
docker network connect [NETWORK_NAME]
Enter fullscreen mode Exit fullscreen mode
  • view details about specific docker network
docker network inspect [NETWORK_NAME]
Enter fullscreen mode Exit fullscreen mode

Docker Compose

  • start all the service defined in a yaml file
docker-compose up
Enter fullscreen mode Exit fullscreen mode
  • to get logs
docker-compose logs
Enter fullscreen mode Exit fullscreen mode
  • build images defined in a docker-compose.yml file
docker-compose build
Enter fullscreen mode Exit fullscreen mode
  • stop and remove all servies defined in the file
docker-compose down
Enter fullscreen mode Exit fullscreen mode
  • list all services managed by compose
docker-compose ps
Enter fullscreen mode Exit fullscreen mode

Debugging and monitoring

  • run a command inside a running container
docker exec -it [container_id/name]
Enter fullscreen mode Exit fullscreen mode
  • View detailed information about a container or image
docker inspect [container_id/name]
Enter fullscreen mode Exit fullscreen mode
  • monitor resource usage of container
docker stats
Enter fullscreen mode Exit fullscreen mode

Clean up

  • remove unused data(stopped container, images, networks)
docker system prune -a
Enter fullscreen mode Exit fullscreen mode
  • remove unwanted containers
docker container prune
Enter fullscreen mode Exit fullscreen mode
  • remove unused images
docker image prune -a
Enter fullscreen mode Exit fullscreen mode
  • remove unused volume
docker volume prune
Enter fullscreen mode Exit fullscreen mode

END

container Article's
30 articles in total
Favicon
How to run a Nginx-web server
Favicon
Docker Basics
Favicon
What is Kubernetes Vs Terraform
Favicon
It is time to express your intention ,before you really code
Favicon
Docker Hands-on: Learn Docker Volume and Bind Mounts with Sample Projects using NGINX
Favicon
Can I start and stop Docker Desktop using CLI?
Favicon
The Power of Containers: Why Docker is Essential in Cloud, AI, Software Engineering and DevOps
Favicon
Docker Tutorial and Easy Guide to Master Dockerfile, Images, Containers, Commands, Volume, Network, and Compose
Favicon
Mastering the Container-Presenter Pattern in Angular: A Deep Dive
Favicon
Terraform: Use Template file for AWS CodeDeploy AppSpec file
Favicon
Building a PSR-11 Compatible Dependency Injection Container with PHP 8.4 Lazy Objects
Favicon
PnR: Configuration-Intention Driven Container Orchestration with Go's Platform Abstraction
Favicon
Why Rootless Containers Matter: A Security Perspective
Favicon
How to Install Tailscale in a Proxmox CE 8.2 LXC Container (AlmaLinux 9)
Favicon
Create a container using the Ubuntu image in Docker.
Favicon
Kubernetes คืออะไร? แบบ Dev เห็นภาพ
Favicon
A brief breakdown of Kubernetes architecture
Favicon
Docker Image Optimization: Reducing Size for Faster Deployments
Favicon
Docker
Favicon
Dockerfile Anti-Patterns: What Not to Do
Favicon
Docker Layer Caching Explained: Tips to Improve Build Times
Favicon
Homemade application firewall for Linux
Favicon
Kubernetes: Introduction
Favicon
Pod Security with K8Studio
Favicon
Docker ARG vs ENV: Understanding Build-time and Runtime Variables
Favicon
Containerize Rust Application in 2 Minutes using Docker Init
Favicon
What is a Container Registry
Favicon
How to Use Docker to Improve Your Development Workflow: A Complete Guide
Favicon
Effortlessly Dockerize Your Vite-React Application
Favicon
Docker Networking every developer should know

Featured ones: