Docker Commands - A Quick 5 Minute Refresher



This guide is intended for anyone who hasn't used Docker in awhile and is just looking for a quick refresher on command syntax of frequently used Docker commands to run, configure, and manage containers and images.

List and Update / Get Your Docker Images

To see what Docker images you have on your machine. 

docker images - To list all Docker images on your system
docker inspect <Image ID> - To get more details of the image in JSON
docker rmi <Image ID> - To delete an image from your system
docker pull <Repository>:<Tag> - To update or get an image you need to reference the image using the Repository and Tag


Managing Your Containers

docker ps - To list all your currently running containers
docker ps -a - List all persistent containers you have on your system
docker rm <Container ID>  - To delete a container from your system


Nuke Everything!

If all your containers and images are stale and you just want to start with a clean system. docker system prune is the command you are looking for. Best to review the official docker documentation on the command here.

Let's Get Running...

If you are looking to create a new container from an image and interactive with it:
docker run --name <name for container> -it <image repository>:<image tag>

If you are looking start an existing container and interactive with it:
docker start -ai <name of container>


Share Host Folder with Container

If share a host system folder with a new container using the -v parameter. The key thing to remember is you supply the full host path separated by a colon and the path you want it to mount as in the container.
docker run --name <name for container> -it -v <host full path>:<container mount path> <image repository>:<image tag>


Set an Environment Variable in the Container

To set an environment variable in a new container using the -e parameter. The key thing to remember is you use declare the variable name uses the equal sign set its value.
docker run --name <name for container> -it -e <EVAR NAME>=<evar value> <image repository>:<image tag>


Comments

Popular posts from this blog

Apple Pay, Android Pay, contactless credit cards, is it safe?

Failed CUDA Toolkit Install? Ubuntu 18.04 stuck on boot of Gnome Display Manager?

How Salesforce uses AWS to Improve The Support Call Experience