Skip to content

Instantly share code, notes, and snippets.

@kyle-morton
Last active August 15, 2020 19:59
Show Gist options
  • Save kyle-morton/0e9624834946c1a1dc4c343a471ef634 to your computer and use it in GitHub Desktop.
Save kyle-morton/0e9624834946c1a1dc4c343a471ef634 to your computer and use it in GitHub Desktop.
Docker CLI Commands

Key Docker Commands

IMAGES

docker pull [image-name]

  • pull image onto machine

docker images

  • list images on your machine

docker rmi [imageID]

  • remove image from machine

CONTAINERS

docker run [image-name]

  • run an image, DLs it if not on machine

docker run -p 8080:80 [image-name]

  • run an image and bind port from docker (8080 here) to container (80)

docker inspect [container-name]

  • gives you information about where the container is mounted and where volume files are written

docker ps -a

  • view all containers on your machine (regardless of running)

docker rm [containerID]

  • remove container from machine

Volumes

docker run -p 8080:80 -v var/www [image-name]

  • run image, bind port, set writable volume at "var/www" that docker host writes peristent files to. Docker will automatically choose where this "var/www" is written as a managed volume

docker rm -v [container-name]

  • removes the container along w/ the managed volume by docker. If you do the command below in which you specificy the volume yourself, -v will not affect it on rm command

docker run -p 8080:80 -v $(pwd):/var/www [image-name]

  • run image, bind port, set writable volume at "var/www" that docker host writes peristent files to in the current working directory (wherever the command was ran)

DotNet

docker pull mcr.microsoft.com/dotnet/sdk

  • pull latest Dotnet SDK image

docker run -it -p 8080:5000 -v ${PWD}:/app -w "/app" mcr.microsoft.com/dotnet/core/sdk /bin/bash

  • run inside an MVC project, will open a bash shell to that folder on your LOCAL machine from within the container (Docker has made this a volume visible to the container)

^ Demonstrates a nice feature in docker, source code can be local, but ran inside a container so you can run your app w/ your needed frameworks on an OS just using docker (no need to install them locally)

Share images

docker login

docker push <username>/<image_name>

  • pushes your image to a public docker hub repo (upload might take a while)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment