My Docker Cheat Sheet With Simple Cases as Back-end Engineer
Currently im working as Backend Engineer, and used docker for development purpose. This cheat sheet is very helpful for me and i hope its will help you too, keep learning š
I grouped this articles with 2 sections, Command and Cases. In Cases section, i will show you my simple cases.
#1. Commands
For this section, i grouped with 2 categories.
Working with Image :
docker build .
: build image with no tag.docker build . -t repository:tag
: build image with tag name.docker run --rm imageName
: run container and auto destroy if stopped.docker images
: list all local docker images.docker images --format ā{{.Repository}}ā
: list all local docker images, and format this results. you can find the detail here.
Working with Container :
docker ps
: show all running containers.docker ps -a
: show all stopped containers.docker logs containerName
: show container logs.docker stop containerName
: stop spesific container.docker container prune
: remove all stoped containers.docker rm $(docker ps -a)
: destroy all stopped containers.docker exec -it containerName command
: execute command in container.docker stop container containerName
: stop spesific container.docker stop $(docker ps)
: stop all running containers.
#2. Cases.
My simple case with my cheat sheet.
-1. Running redis container with custom port & name & destroy this container after stopped.
docker run --rm --name my-redis -p 6200:6379 redis
-2. List all local docker images , but only show repository and tags name format.
docker images --format ā{{.Repository}} :{{.Tag}}ā
-3. In my cases i need to build docker images with multiple tags, result this command will show multiple images with same image id in local computer.
docker build . -t awesome_project:v1-app -t awesome_project:v1-sidekiq
-4. Execute command for cat file inside container. This command will show text from container file.
docker exec -it containerName cat config/local_env.yml