Basic Docker Commands for Beginners
Docker is a popular containerization platform that allows developers to package applications and their dependencies into lightweight, portable containers. This guide covers essential Docker commands for getting started.
1. Installing Docker
macOS (via Homebrew)
brew install --cask docker
Linux (Debian-based)
sudo apt update && sudo apt install docker.io
Windows
Download and install Docker Desktop from docker.com.
2. Checking Docker Installation
docker --version
docker info
3. Managing Docker Containers
Run a container
docker run hello-world
List running containers
docker ps
List all containers (including stopped)
docker ps -a
Stop a container
docker stop container_id
Remove a container
docker rm container_id
4. Working with Docker Images
List downloaded images
docker images
Pull an image from Docker Hub
docker pull image_name
Remove an image
docker rmi image_name
5. Building Docker Images
Build an image from a Dockerfile
docker build -t image_name .
6. Docker Networks
List networks
docker network ls
Create a network
docker network create network_name
Connect a container to a network
docker network connect network_name container_id
7. Docker Volumes
List volumes
docker volume ls
Create a volume
docker volume create volume_name
Remove a volume
docker volume rm volume_name