Skip to content

Instantly share code, notes, and snippets.

@kevin-svds
Last active September 24, 2021 17:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevin-svds/6fae553f1a00364519d9 to your computer and use it in GitHub Desktop.
Save kevin-svds/6fae553f1a00364519d9 to your computer and use it in GitHub Desktop.

Useful Docker commands

The Basics

Build and tag an image from a Dockerfile :

docker build -t name/tag .

Run image:

docker run name/tag

List running containers:

docker ps

Enter interactive bash shell in an existing container:

docker exec -it container_name bash

Starting & stopping docker-compose services

Start existing containers in the background without recreating from images:

docker-compose up -d --no-recreate

Stop a running container, rebuild it, then start it again in the background without restarting its dependencies:

docker-compose stop service_name
docker-compose build service_name
docker-compose up -d --no-deps service_name

Cleanup

Delete all non-running containers (won't affect images):

docker rm $(docker ps -a -q)

Delete "dangling" images that aren't dependencies for any tagged image or existing container:

docker rmi $(docker images -q -f dangling=true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment