Skip to content

Instantly share code, notes, and snippets.

@oreillyross
Created April 17, 2024 11:07
Show Gist options
  • Save oreillyross/e8c745bee20bddaa008df59a7728343e to your computer and use it in GitHub Desktop.
Save oreillyross/e8c745bee20bddaa008df59a7728343e to your computer and use it in GitHub Desktop.
The general Docker run command with flags
docker run -d p <host-port>:<container-port> -e <name>=<value> <image-name>
@oreillyross
Copy link
Author

docker container list

@oreillyross
Copy link
Author

oreillyross commented Apr 17, 2024

docker logs <unique id of docker image>

@oreillyross
Copy link
Author

To run public docker images, you can search for them and then run them with the below command
docker run -p 27017:27107 mongo:latest

@oreillyross
Copy link
Author

docker exec -it <container-id> bash

@oreillyross
Copy link
Author

docker stop <container-id>

@oreillyross
Copy link
Author

docker container list --all

@oreillyross
Copy link
Author

oreillyross commented Apr 17, 2024

docker rm <container-id>

@oreillyross
Copy link
Author

Cleaning up everything all at once
Need a way to nuke all Docker containers and images at once? A few steps are
involved in doing this. The following commands work on macOS, Linux, and the WSL2
Linux terminal under Windows (but not under Windows Terminal).
First, stop and remove all containers:
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
Then, run the prune command with the following options to remove everything else:
docker system prune --volumes --all
This will remove all cached images on your computer. Be prepared to wait a lot longer
for all subsequent Docker builds because it will download all the base images into your
local cache again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment