Mostly used commands of Docker used in DevOps world
Hello Everyone,
This is day 20 of 90DaysOfDevops Challenge initiated by Shubham Londhe .Below is a cheatsheet containing some commonly used Docker commands in the DevOps world:
Image Management:
docker images
- List all available images.docker pull <image>
- Download an image from a registry.docker build -t <tag> <path>
- Build an image from a Dockerfile.docker push <image>
- Push an image to a registry.docker rmi <image>
- Remove an image.
Container Management:
docker run <image>
- Create and start a container from an image.docker ps
- List all running containers.docker stop <container>
- Stop a running container.docker start <container>
- Start a stopped container.docker restart <container>
- Restart a running container.docker rm <container>
- Remove a stopped container.docker exec -it <container> <command>
- Run a command inside a running container.
Container Logs and Stats:
docker logs <container>
- Fetch logs of a container.docker logs -f <container>
- Stream logs of a container.docker stats
- Display resource usage statistics of running containers.
Container Networking:
docker network ls
- List all available networks.docker network create <name>
- Create a network.docker network connect <network> <container>
- Connect a container to a network.docker network disconnect <network> <container>
- Disconnect a container from a network.docker network inspect <network>
- Display details of a network.
Volume Management:
docker volume ls
- List all volumes.docker volume create <name>
- Create a volume.docker volume inspect <volume>
- Display details of a volume.docker volume rm <volume>
- Remove a volume.
Docker Compose:
docker-compose up
- Create and start containers defined in a docker-compose.yml file.docker-compose down
- Stop and remove containers defined in a docker-compose.yml file.docker-compose logs
- Fetch logs of containers defined in a docker-compose.yml file.docker-compose -f docker-composeXYZ.yml up -d
- when u want to give some other name to your docker compose file. - Fetch logs of containers defined in a docker-compose.yml file.docker-compose -f docker-composeXYZ.json up -d
- u can use json file instead of yml file.docker-compose create
- create container but not network also it cannot run containerdocker-compose up --no-start
- create container and network as well but do not run it.docker-compose start
- will run the container.docker-compose stop
-docker-compose rm
- remove all container but not network.docker-compose pause
-docker-compose unpause
-docker-compose ps
-docker-compose kill
-docker-compose port
-docker-compose logs -f
-docker-compose exec <serviceName> ls
-docker-compose run <serviceName> ls
-docker-compose scale serviceName=5 serviceName=5
-docker-compose top
-docker-compose create
-
Registry and Repository:
docker login
- Log in to a Docker registry.docker logout
- Log out from a Docker registry.docker search <term>
- Search for images in a Docker registry.
System and Info:
docker version
- Display the Docker version.docker info
- Display system-wide information about Docker.docker system df
- Show Docker disk usage.
Remember, this is not an exhaustive list, but it covers some of the most commonly used Docker commands in the DevOps world. You can explore more options and command variations by referring to the official Docker documentation.