Skip to content

Latest commit

 

History

History
213 lines (150 loc) · 4.76 KB

README.md

File metadata and controls

213 lines (150 loc) · 4.76 KB

⭐ Docker Cheatsheet ⭐

This Repository is a guide to all the Docker CLI commands you need to use in case any of these situations arise

Index 📚


Create Containers ✨

  • Create container from image and start it

> docker container run <image name>

NOTE: Replace <image name> with required image name ignoring <>


  • Create container from image but not run it

> docker container create <image name>

NOTE: Replace <image name> with required image name ignoring <>


⬆ Back to Index


Start Container 🏃

  • Start container which is currently not running

> docker container start <container id>

NOTE: Replace <container id> with target container id ignoring <>


  • Start container which is currently not running and show output

> docker container start -a <container id>

NOTE: Replace <container id> with target container id ignoring <>


  • Start container with shell access (ssh style)

> docker container run -it <container_id> sh

NOTE: Replace <container_id> with target container id ignoring <>


  • Start container with port mapping

> docker container run -p <to_port:from_port> <image_name>

NOTE: Replace <image_name> with target image name and replace to_port with the port you want to access from your machine and replace from_port with the port in which the container uses Ignore <>


⬆ Back to Index


Stop Running Container 🔴

  • Stop container after executing

> docker container stop <container id>

NOTE: Replace <container id> with target container id ignoring <>


  • Intstantly terminate running container (force stop)

> docker container kill <container id>

NOTE: Replace <container id> with target container id ignoring <>


⬆ Back to Index


Container Management 💼

  • View list of all running containers

> docker container ls

NOTE: Add parameter -a to list all containers ever created


  • Remove all stopped containers from list

> docker system prune

  • Clear list

> docker system prune --all

  • Remove specific container from list

> docker container rm <continer_id>

NOTE: Replace <container_id> with target container id ignoring <> This might fail if the container is currently running. In that case view force delete command below


  • Force delete container from list

> docker container rm -f <container_id>

NOTE: Replace <container_id> with target container id ignoring <>


⬆ Back to Index


Logs 📃

  • View specific container logs

> docker container logs <container id>

NOTE: Replace <container id> with target container id ignoring <>


⬆ Back to Index


Dockerfile 🐳

  • Set base image

FROM <image>

NOTE: Replace <image> with base image


  • Set Author Name

MAINTAINER <name>

NOTE: Replace <name> with the name you want to set for the author field


  • Execute shell command

RUN <command>

NOTE: Replace <command> with the command you want to execute on the containers shell


Click here to visit the repository containing language and framework specific templates for docker and docker compose

⬆ Back to Index


Contributors

Gowtham Karthikeyan

Gowtham Karthikeyan

GitHub