Docker Management

Below are some basics on Docker image and container management. Essentially you can use most commonly known Unix-like OS' such as Debian, CentOS, Fedora, etc... or install Docker Desktop on Windows or use Windows Server 2016 or greater for container hosting. The dedicated container-focused OS, CoreOS, has reached it's end-of-life; the alternative and drop-in replacement is Flatcar Container Linux.

Pull an image:

docker pull debian

List all images:

docker images

Runinng a container. 

docker run -it --rm -d -p 8080:80 --name mycontainer nginx

Access an image by creating a container:

docker exec -it mycontainer bash

Commit changes to an image:

docker commit CONTAINER_ID my-app

Stopping a container:

docker stop mycontainer

List all running images:

docker ps -a

Remove all containers:

docker ps -q -a | xargs docker rm

Remove an individual image:

docker rmi ubuntu:latest

Remove all images:

docker rmi --force $(docker images | awk '{print $3}')

Create a basic Dockerfile (nginx). The first line specifies which image and the second copies the index document to use in the container, using nginx:latest as the source:

FROM nginx:latest
COPY ./index.html /usr/share/nginx/html/index.html

Build a Dockerfile:

touch Dockerfile

#Add contents
FROM nginx:latest
COPY ./index.html /usr/share/nginx/html/index.html
docker build --no-cache -t my-app/nginx-custom:1.0.0 .

Note: The --no-cache option ensures the Docker build won't rely on any cached content. The -t parameter specifies the docker image name, my-app, the image name as nginx-custom and 1.0.0 as the image version.

Run the container from the customized image:

docker run -it --rm -d -p 80:8080 --name mycontainer1 my-app