Getting Started with Docker

Getting Started with Docker



Containers are not virtual machines. They are packaged applications that sit on the host OS and use the resources of the host OS as if they were their own. Containers are images with an extra read/write layer added. Traditionally containers sit on a Linux host OS. Therefore with Docker for Windows and Docker for Mac, a lightweight Linux VM (MobyLinux) is installed and used as a shim between Docker and the container to allow that guest container to appear to be sitting on a Linux host and thereby use the resources of the host computer. Be that Windows or macOS. Since 2017 it has been possible for Windows 10 and Server 2016 to host containers natively as Windows Containers without the Linux VM shim.


Images store the application binaries, configuration and, in a production, your source code. They do not contain the OS; that's provided by your host computer.

Union file system. Previous files are cached and built up over time in layers of changes. Each layer is like a Git commit with a SHA reference. Think of it like a series of diffs to a file or an incremental backup. This helps to keep the file size down for storage and transmission.


A Tag is a reference to a point in the history of an image in the same way a tag points to a commit in a Git repo.


A Dockerfile is recipe of instructions on how to build the image. The order of elements in a Dockerfile is important. Steps in the file are cached and therefore if a step hasn't changed, the cached version at that point is used which has a build speed advantage. If you do need to change or add a step, that step and subsequent step are build as they would be the first time.


A Volume maps a location within the container to a Docker generated location on the host. These volumes can be assigned a name for easy reference and location on the host. Anything saved to the Volume persists beyond the running life of the container and even beyond its deletion. Therefore Volumes need to be explicitly deleted if they are not longer required. On Windows and macOS the host location is withing the Linux VM shim and therefore not easily inspected via the OS. Volumes are specified with the Dockerfile.

Bind Mount

A Bind Mount maps a location on the host to a location within the container. Once again, files within a Bind Mount location persist beyond the life of the container. A Bind Mount location is specified in a docker container run with a --volume <host location>:<container location> option. For Windows, the host location path is separated with forward slashes (/) and the drive with double forward slashes (//d/www/la/Code/).

Installation Signin as your ADM user Download Docker Desktop on Windows Run the installer Add your normal signin account to the docker-users Group in Computer Management Switch to your normal user Start Docker Desktop Choose Settings from the Docker system tray Decide if you want Docker to start on log in Allow your local D: drive to accessible from your containers Change your Disk image location to D:\docker\vm-data\DockerDesktop.vhdx Proof of Life docker container run --publish 80:8080 --detach --name docker-test ortussolutions/commandbox This says, spin up a container using the ortussolutions/commandbox image (downloading it from the Docker Repository first if required) in the background with the name docker-test and forward all requests for port 80 onto port 8080 inside of the container and thereby the application within The first time this is run it will be slow. This is because the ortussolutions/commandbox image has to be downloaded from the Docker repository. As part of the request the image is cached locally once downloaded. Subsequent requests for ortussolutions/commandbox are recalled from the local cache, speeding up the start up process Keep requesting docker container ls --all until the container docker-test reports (healthy) then visit localhost from your browser Use docker container top docker-test to list the running processes Clean up docker container ls --all docker container stop docker-test docker container rm docker-test docker container ls --all Useful commands Containers docker containers ls - list running containers docker containers ls --all - list running and stopped containers docker container top <container id/name> - list running processes docker container stats - show realtime information on running containers docker container inspect docker-test --format "{{ .Platform }}" - show details of the container (selecting just the Platform value) docker container exec -it <container id/name> - jump into a running container giving a shell as the command docker stop <container id/name> - stop running container docker container rm <container id/name> - remove a stopped container docker container rm --force <container id/name> - force remove a running container Images System docker system df - display disk usage Useful options --help - return help information on the current command --detach - start the container in the background --name - the container a name --rm - remove the container when it is stopped --publish - forward requests from the host port to the container port --env = - pass an environment name/value pair to the container -it - start the container with an interactive session using the given shell

New work item

Spinning up MS SQL

docker run --detach --publish 1433:1433 --volume /Volumes/shared:/shared --name mssql --env 'ACCEPT_EULA=Y' --env 'SA_PASSWORD=MyBestPassword99'

docker run --detach --publish 1433:1433 --volume /Volumes/d:/shared --name mssql --env 'ACCEPT_EULA=Y' --env 'SA_PASSWORD=Kat57man'