Skip to content

Instantly share code, notes, and snippets.

@alancoleman
Last active May 14, 2024 09:11
Show Gist options
  • Save alancoleman/56827605553aeabe96bccb6fcfa0f236 to your computer and use it in GitHub Desktop.
Save alancoleman/56827605553aeabe96bccb6fcfa0f236 to your computer and use it in GitHub Desktop.
Some basic docker commands
## Containers
# Show running containers
docker ps
# Show all containers
docker ps --all
docker ps -a
# Show all container ids
docker ps -q
# Create a container
docker run -d [name]
# Stop a container
docker stop [id]
# Stop a container instantly
docker stop -t 0 [id]
# Open bash inside a container
docker exec --interactive -tty [id] bash
# Show date and time of a container
docker exec [id] date
# Remove a container
docker rm [id] -f
# Stop and remove a container
docker rm
# Loop through all running containers, in this instance showing ids
docker ps -aq | xargs
# Loop through and stop all containers
docker ps -aq | xargs docker stop -t 0
# Loop through and remove all containers
docker ps -aq | xargs docker rm
## Images
# Build an image from a file. Note that the period is where the file path goes, in this instance this command would be run in the same directory
docker build -t [name] .
## Conext
# Context is important if you're using Docker desktop
# https://docs.docker.com/desktop/install/linux-install/
docker context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment