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:
List all images:
docker imagesRuninng a container.
docker run -it --rm -d -p 8080:80 --name mycontainer nginxAccess an image by creating a container:
docker exec -it mycontainer bashCommit changes to an image:
docker commit CONTAINER_ID my-appStopping a container:
docker stop mycontainerList all running images:
docker ps -aRemove all containers:
docker ps -q -a | xargs docker rmRemove an individual image:
docker rmi ubuntu:latestRemove 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:
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