DEV Community

Cover image for Docker Hot Tips
YURII DE.
YURII DE.

Posted on

Docker Hot Tips

These tips will be useful for developers who are already familiar with docker and understand the fundamental principle behind it. In my opinion, these are the hottest tricks for the newcomer who for some reason has not yet memorized these commands.

PLC - Peace! Love! Code!

Docker build container

docker build ./ -t "<name>:<version>" --platform=linux/amd64
Enter fullscreen mode Exit fullscreen mode

SSH into a container

docker exec -it <mycontainer> bash
# or
docker exec -it <mycontainer> sh
Enter fullscreen mode Exit fullscreen mode

Remove: all containers & all images

# List all containers (only IDs)
docker ps -aq

# Stop all running containers
docker stop $(docker ps -aq)

# Remove all containers
docker rm $(docker ps -aq)

# Remove all images
docker rmi $(docker images -q)
Enter fullscreen mode Exit fullscreen mode

docker-compose build

# --build-arg ENV_VAR=<value> - add args
docker-compose --project-name "<name>" build \
--build-arg ENV_VAR=<value>
Enter fullscreen mode Exit fullscreen mode

docker-compose up

# -d - Detached mode: Run containers in the background
docker-compose --project-name "<name>" up -d
Enter fullscreen mode Exit fullscreen mode

docker-compose down

docker-compose --project-name "<name>" down
Enter fullscreen mode Exit fullscreen mode

Use for notes:

https://notepad.site/

Top comments (0)