Skip to content

Instantly share code, notes, and snippets.

@dimebt
Last active May 22, 2023 13:46
Show Gist options
  • Save dimebt/5338b168e5cd44c4e20387ebe1455770 to your computer and use it in GitHub Desktop.
Save dimebt/5338b168e5cd44c4e20387ebe1455770 to your computer and use it in GitHub Desktop.
Basic docker shell commands
# Docker commands
# Show all containers (default shows just running)
docker ps -a
# Start the docker service
systemctl start docker
# List images
docker images
docker image ls
# Stop docker containers
docker container stop [containers]
# This will remove all stopped containers.
docker container prune
# Remove one or more images
docker image rmi
# Force removal of the image
docker image rmi -f
# Remove one or more containers
docker image rm
# Force the removal of a running container (uses SIGKILL)
docker image rm -f
# Execute a command in a running container (interactive)
docker exec -it [CONTAINER] bash
# See logs from container with timestamps
docker logs [CONTAINER] --timestamps
# Copy file or folder from a docker container to the local file system.
docker cp <containerId>:/file/path/in/container/file /host/local/path/file
# docker-compose commands
# Info: Docker Compose is now in the Docker CLI, try `docker compose [commands]`
# Build or rebuild the docker-compose file
docker-compose build
# If you want to run your services in the background (detached)
docker-compose up -d
# If you want to run your services in the background (detached) and rebuild the idocker mages
docker-compose up -d --build --no-cache
# List containers
docker-compose ps
# Stop and remove containers, networks, images, and volumes
docker-compose down
# Below is an example of a command to clean all containers, images, volumes, networks, and undefined containers created with docker-compose.
docker-compose down --rmi all -v --remove-orphans
# Receive real time events from containers
docker-compose events
# Execute a command in a running container
docker-compose exec
# List images
docker-compose images
# View output from containers
docker-compose images
# Restart services
docker-compose restart
# Stop services
docker-compose stop
# Remove stopped containers
docker-compose rm
# Create and start containers
docker-compose up
# Create and start specific services in docker compose file, with specific env file
docker-compose -f docker-compose.yml --env-file .env_prod up --force-recreate -d --build
-----------------------------
# Linux Docker commands
## Reload the systemctl configuration.
sudo systemctl daemon-reload
## Restart Docker.
sudo systemctl restart docker.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment