Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

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


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