Skip to content

Instantly share code, notes, and snippets.

@Zeex
Last active September 6, 2018 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zeex/e2dcbfff2117411a8bd1003998c9bc70 to your computer and use it in GitHub Desktop.
Save Zeex/e2dcbfff2117411a8bd1003998c9bc70 to your computer and use it in GitHub Desktop.
Just some notes for myself in case I forget how to use Docker

Forgot how to use Docker again?

Test if Docker installation is working

docker run hello-world

Run an Ubuntu container and open shell

docker run -it ubuntu /bin/bash

Run an Ubuntu container and mount an external directory to access it from the inside

Mount current directory ($PWD):

docker run -v $PWD:/files -it ubuntu /bin/bash

Mount another directory using its path:

docker run -v /path/to/files:/files -it ubuntu /bin/bash

Automatically kill (remove) containers after the shell process dies (or generally after the container exits)

Use --rm flag in docker run.

List running containers

docker ps

List running and zombie containers

docker ps -a

Kill a zombie container

docker rm <container_id>

Container ID doesn't have to be the full ID, just needs to be the first few charactesr so that it's unique enough.

Save a container as a new image so that any changes are persisted and you can use this image for new containers later

docker commit <container_id> my_awesome_image
docker images # lists all images, should display your new image in the list

Delete an image

docker image rm <image_name>
docker image rm <image_id>

Again, image ID doesn't have to be the full ID, just first few characters is enough in most cases.

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