Docker Cheat Sheet

04 Aug 2022 - Alejandro Piña

Basic docker commands that are used day to day

Working with images

Build a docker image from a given docker file

  • -f name of docker file
  • -t name and tag
docker build -t [image_scope/image_name:tag] -f [Dockerfile] . --no-cache

Images list

docker images

Delete an image

docker rmi [image_scope/image_name:tag]

Export an image

docker save [image_scope/image_name:tag] | gzip > [compressed_image.tar.gz]

Tag an image before that be published

Note: review format target before push to AWS

docker tag [source]:latest [target]:latest

Working with containers

Container list

docker ps -a

Run a container from a given image

docker run -d -p 8080:80 --name [container_name] [image_name]

Run interactive bash commands in containers from terminal

docker exec -it [container_name] [command]

Stop/Start a container

docker stop [container_name]
docker start [container_name]

Delete a container

docker conatiner rm [container_name]

Working with Docker and AWS

AWS docker login

aws ecr get-login-password --region [region] | docker login --username AWS --password-stdin [aws_account_id.dkr.ecr.region.amazonaws.com]

Upload an image to AWS ECR

docker push aws_account_id.dkr.ecr.region.amazonaws.com/[target]:[tag]