Docker Cheat Sheet

 

Created on: 10/3/17
Last update: 10/3/17

Get Started

Create a Dockerfile

Build a Docker Image

docker build -t testbed13 .

Images

List Docker Images

docker images

Save/Load images

docker save -o <save image to path> <image name>
docker load -i <path to image tar file>

Remove Images

docker rmi IMAGE_ID
docker rmi $(docker images -q)

Container

List Containers

List the running containers:

docker ps

List all containers:

docker ps -a

Run a Container from a Docker Image

docker run -i -t ID_or_Name /bin/bash
docker run -it -d --name=demo testbed13 /bin/bash

Run a container with exposed port

Port: external:internal

docker run -p 8082:8080 gmuwps

Get into a Docker Containers

docker exec -t -i ID_or_Name /bin/bash

Stop Containers

Stop container:


Stop all containers:

docker rm $(docker ps -a -q)

Remove Containers

Remove Containers:

docker rm ID_or_Name ID_or_Name

Remove All Exited Containers:

docker rm $(docker ps -a -f status=exited -q)

Docker Login

Login to Docker Hub

docker login --username=czhang11 --email=czhang11@gmu.edu

Pull Image

Docker Pull

docker pull java:7

Docker Q&A

DNS Resolving Issue

Error

Resolving issue while building docker container:

...
Temporary failure resolving 'security.debian.org'
...

Solution

Get the DNS server info:

nmcli dev show | grep IP4.DNS

Output would be like:

IP4.DNS[1]:                             192.168.1.236
IP4.DNS[2]:                             129.174.67.98
IP4.DNS[3]:                             129.174.1.3

Update the nameserver in /etc/resolv.conf

# nameserver 127.0.0.1
nameserver 129.174.67.98

Reference

How To Remove Docker Images, Containers, and Volumes

DOCKER FILE TO DEPLOY A WAR FILE ON TOMCAT