Last active
October 17, 2024 13:32
-
-
Save alancoleman/56827605553aeabe96bccb6fcfa0f236 to your computer and use it in GitHub Desktop.
Some basic docker commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 | |
# Create a container with a restart value and an interactive session | |
docker run --name [name] -it --restart always [image] sh | |
# Connect to a container using bash | |
docker exec -it [name] bash | |
# Connect to a container using shell | |
docker exec -it [name] sh | |
## 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