Docker – Commonly Used Commands

To build an image (use -t to specify name:tag):
Run: docker build -t NAME /path/to/Dockerfile

To run an image (use —name to define name for the container):
Run: docker run -d —name ContainerNAME ImageNAME
** -d means detached mode
Or Run: docker run -dit …
** -t means allocate a pseudo-TTY which can keep the container running if no other commands are provided.
** -i, –interactive Keep STDIN open even if not attached

To show running containers:
Run: docker container ls

To show all containers:
Run: docker container ls -a

To remove a container:
Run: docker rm ID_OR_NAME

To remove all stopped containers:
Run: docker container prune

To remove dangling images:
Run: docker image prune
add -a flag to remove all images not referenced by any container

To remove an image:
Run: docker rmi ID_OR_NAME

Published by Mageek

Just another geek in the world

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: