Day 20 Task: Docker Cheat sheet 🐬

sri parthusri parthu
3 min read

Process Management

CommandsUse Cases
docker --versionCheck Docker version.
docker infoDisplay system-wide information about Docker.
docker psShow all running Docker containers.
docker ps -aShow all Docker containers.
docker run <image>:<tag>Run a containers.
docker run -it <image>:<tag>Run a container and connect to it.
docker run -d <image>:<tag>Run a container in the background.
docker stop <CONTAINER_ID>Stop a container.
docker kill <CONTAINER_ID>Kill a containers.
docker rm <CONTAINER_ID>Remove a containers.

Volumes & Ports

CommandsUse Case
docker volume lsLists of volumes.
docker volume create <volume>Create a volume.
docker volume rm <volume>Delete a volume.
docker volume inspect <volume>Show volumes metadata.
docker volume pruneDelete all volumes not attached to a container.
docker volume -v <local_dir>:<container_dir> <image>Mount a local directory into your container.
docker cp <container>:<container_dir> <local_dir>Copy file or folder from a docker container to host machine.
docker cp <local_dir> <container>:<container_dir>Copy file or folder from local machine onto a container.
docker run -d -p <ip address>:<local port>:<docker port> <image>Map a local port to docker instance.
docker port <CONTAINER_ID>Lists the ports a docker container is running on.

Docker compose

CommandsUse Cases
docker-compose up -d -d <docker-compose_yaml>Start your docker-compose defined resource in detached mode.
docker-compose stopStop all docker-compose resource.
docker-compose downDestroy all docker-compose resource.
docker-compose psShow Docker-compose processes.
docker-compose logsShow Docker-compose logs.
docker-compose topShow Docker-compose resource consumption.

Images/Repository

CommandsUse Cases
docker imagesList available local images.
docker search <image>Search for Docker images.
docker pull <image_name>Pull a Docker images.
docker build -t <image>:<tag> <run_directory> -f <dockerfile>Build an image with a Docker file.
docker login <repository>Login to remote repository.
docker push <image>:<tag>Push an image to your remote repository.
docker rmi <image>:<tag>Remove a local Docker image.
docker inspect <image>Show metadata for an image.
docker image pruneRemove all unused Docker images.

Troubleshooting

CommandsUse Cases
docker logs <container>Show the logs of container.
docker logs -f <container>Follow/tail the logs of the container.
docker logs -t <container>Show timestamps on docker logs.
docker top <container>Show a 'top' view of processes running on a container.
docker statsShow a top view of all docker containers.
docker diff <container>Show any files that have changed since startup.
docker attach <container>Connect to an already running container.
docker exec -it <Container_id> /bin/bashExecute a command on a container.
docker system infoShow Docker system wide information.
docker system dfShow Docker Disk spaced used.

Networks

CommandsUse Cases
docker network create <network_name>Create a User define network.
docker network lsList networks.
docker network connect <network_name> <container_name/id>Connect a Container to a network.
docker network disconnect <network_name> <container_name/id>Disconnect a container from a network.

Happy Learning

Thanks For Reading! :)

-SriParthuπŸ’πŸ’₯

0
Subscribe to my newsletter

Read articles from sri parthu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

sri parthu
sri parthu

Hello! I'm Sri Parthu! 🌟 I'm aiming to be a DevOps & Cloud enthusiast πŸš€ Currently, I'm studying for a BA at Dr. Ambedkar Open University πŸ“š I really love changing how IT works to make it better πŸ’‘ Let's connect and learn together! πŸŒˆπŸ‘‹