Docker is a powerful tool for containerization, which allows you to package applications and their dependencies into a consistent environment. Here are some essential Docker commands every developer and system administrator should be familiar with:
Create and start a new container from an image. docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Download an image from a registry (like Docker Hub).
docker pull IMAGE_NAME[:TAG]
Build an image from a Dockerfile.
docker build [OPTIONS] PATH | URL | -
List running containers.
docker ps [OPTIONS]
List available images on your system.
docker images [OPTIONS] [REPOSITORY[:TAG]]
Stop one or more running containers.
docker stop CONTAINER [CONTAINER...]
Start one or more stopped containers.
docker start CONTAINER [CONTAINER...]
Restart a running or stopped container.
docker restart CONTAINER [CONTAINER...]
Remove one or more containers.
docker rm CONTAINER [CONTAINER...]
Remove one or more images.
docker rmi IMAGE [IMAGE...]
Run a command in a running container.
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Fetch the logs of a container.
docker logs [OPTIONS] CONTAINER
Copy files/folders between a container and the local filesystem.
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
Manage Docker networks.
docker network [COMMAND]
A tool for defining and running multi-container Docker applications. (Requires a docker-compose.yml file)
docker-compose [OPTIONS] [COMMAND]
These commands are just the basics. Docker has a rich set of features and options that you can explore as you become more comfortable with containerization.