20 Must-Know Docker Commands with Practical Examples for SDETs
Karthik T
2 min read
Docker is an essential tool for SDETs, enabling the creation, deployment, and management of applications within containers. Whether you're just starting out or looking to refresh your Docker knowledge, this guide covers the 20 most important Docker commands with practical examples
Table of Docker Commands
Command | Description | Example |
docker --version | Displays the installed version of Docker. | docker --version |
docker pull <image> | Downloads an image from Docker Hub. | docker pull nginx |
docker images | Lists all downloaded Docker images. | docker images |
docker run <image> | Creates and starts a container from an image. | docker run nginx |
docker ps | Lists all running containers. | docker ps |
docker ps -a | Lists all containers (running and stopped). | docker ps -a |
docker stop <container_id> | Stops a running container. | docker stop 3b1c3b1c |
docker rm <container_id> | Removes a stopped container. | docker rm 3b1c3b1c |
docker rmi <image_id> | Removes an image. | docker rmi nginx |
docker exec -it <container_id> bash | Accesses the shell of a running container. | docker exec -it 3b1c3b1c bash |
docker build -t <tag> <path> | Builds a Docker image from a Dockerfile in a specified path. | docker build -t myapp . |
docker tag <source_image> <target_image> | Creates a new tag for an image. | docker tag nginx myrepo/nginx:v1 |
docker push <image> | Pushes an image to a Docker registry. | docker push myrepo/nginx:v1 |
docker-compose up | Starts containers defined in a docker-compose.yml file. | docker-compose up |
docker-compose down | Stops and removes containers defined in a docker-compose.yml file. | docker-compose down |
docker network create <network_name> | Creates a custom Docker network. | docker network create mynetwork |
docker run -v <host_path>:<container_path> | Maps a host directory or volume to a container path. | docker run -v /host/data:/container/data nginx |
docker system prune | Removes unused data (containers, images, networks, volumes). | docker system prune |
docker network ls | Lists all Docker networks. | docker network ls |
docker volume ls | Lists all Docker volumes. | docker volume ls |
0
Subscribe to my newsletter
Read articles from Karthik T directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Karthik T
Karthik T
Experienced SDET with expertise in building hybrid UI & API automation frameworks using Playwright, Selenium, RestAssured and Docker ,Proficient in delivering scalable test solutions with comprehensive reporting