DEV Community

Cover image for Docker basics/ cheatsheet
Rubin
Rubin

Posted on

Docker basics/ cheatsheet

Create image using this directory's Dockerfile

docker build -t

Run mapping port 8000

  • docker run -p 8000:80

Same thing, but in detached mode

  • docker run -d -p 8000:80

Enter a running container (you can also do sh)

  • docker exec -it [container-id] bash

See a list of all running containers

  • docker ps

Gracefully stop the specified container

  • docker stop

See a list of all containers , active and inactive

  • docker ps -a

Force shutdown of the specified container

  • docker kill

Remove the specified container from this machine

  • docker rm

Remove all containers from this machine

  • docker rm $(docker ps -a -q)

Show all images on this machine

  • docker images -a

Remove the specified image from this machine

  • docker rmi

Remove all images from this machine

docker rmi $(docker images -q)

Log in this CLI session using your Docker credentials

  • docker login

Tag for upload to registry

  • docker tag username/repository:tag

Upload tagged image to registry

  • docker push username/repository:tag

Run image from a registry

  • docker run username/repository:tag

Top comments (0)