Top 10 docker Commands You need To Learn
Hasan Elsherbiny
Posted on September 6, 2023
1- Docker Run
The docker run command is your gateway to launching containers from Docker images. It allows you to specify image names, options, and runtime configurations.
docker run -d -p 8080:80 nginx
-d: Run the container in detached mode (in the background).
-p: Map ports from the host to the container.
2- Docker Pull
Before running a container, you often need to download the Docker image from a registry like Docker Hub. The docker pull command accomplishes this.
docker pull ubuntu:latest
3- Docker PS
To view the list of running containers, you use the docker ps command. It provides information about container IDs, names, status, and ports. To see all containers, including stopped ones, you can use docker ps -a.
docker ps
4- Docker Stop and Docker Start
These two commands allow you to control the state of a container. docker stop halts a running container, while docker start resumes a stopped one.
docker stop {container_name_or_id}
docker start {container_name_or_id}
5- Docker Logs
The docker logs command is invaluable for troubleshooting and monitoring. It retrieves the logs generated by a container
docker logs {container_name_or_id}
6- Docker Exec
You can execute commands inside a running container using docker exec. This is particularly useful for debugging or running administrative tasks.
docker exec -it {container_name_or_id} {bash}
-it: Interactive mode with a terminal.
bash: The shell you want to use inside the container.
7- Docker Build
When you need to create a custom Docker image, the docker build command is your friend. It uses a Dockerfile to define image instructions.
docker build -t custom_image_name .
8- Docker Images
To list locally available Docker images, use docker images. This command displays image names, sizes, and tags.
docker images
9- Docker RMI
Removing Docker images that are no longer needed frees up disk space. docker rmi allows you to remove images by their name or ID.
docker rmi image_name_or_id
10- Docker Network
Docker provides a networking feature to connect containers and services. The docker network command helps manage these networks.
docker network ls
docker network create my_network
Posted on September 6, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.