Skip to content

Instantly share code, notes, and snippets.

@salahelfarissi
Last active December 10, 2023 15:29
Show Gist options
  • Save salahelfarissi/a80956d8c25ccc2ac12db8f8f9303933 to your computer and use it in GitHub Desktop.
Save salahelfarissi/a80956d8c25ccc2ac12db8f8f9303933 to your computer and use it in GitHub Desktop.
Docker CLI commands
# Get docker engine version
docker version
# List
docker ps # Only running containers
docker ps -a # Shutted containers as well
docker images -a # List images, including intermediary
# Remove
docker rm -f <container> # -f will kill then rm
docker rmi -f <image>
docker rmi $(docker images -q) # --quiet: display ids only
docker container prune -f # -f skip confirmation
docker image prune -a # rm unused images
# Kill running container
docker kill <container>
docker kill $(docker ps -q)
# Run a new container from an image
docker run -it --name <container_name> --rm <image> <command>
docker run --init --rm <container> ls # --init for shutting down server
docker run --init --rm -p <host_port>:<container_port> <container>
docker run --init --rm -d -P <container> # -P publish all exposed ports
docker run -d --network=<network> -p <host_port>:<container_port> \
> --name=<container> --rm <image>
# Copy files between a container and the local file system
docker cp container:/home .
# Run ps aux command in container
docker exec <container> ps aux
# Build container from Dockerfile
docker build -t <container_name> -f Dockerfile . # --tag
# Networking
docker network ls
docker network inspect <network> # Display detailed information
# It's recommended to create a seperate bridge network
docker network create --driver=bridge <network>
# Compose
# docker-compose is V1, now deprecated
docker compose up --build
docker compose up --scale
# Convert a compose.yaml file
kompose convert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment