Getting started with Docker - Part 1
Getting started with Docker through images, containers, Docker Toolbox, Docker Machine, host addresses, and basic Docker 1.x commands for practical first steps.
Getting started with Docker - Part 1
“It works on my machine” is usually a sign that the application environment is not described clearly enough. One developer may have a different library version, configuration value or operating system behaviour than another developer. When the same application moves to testing, these differences create a ripple effect and the team takes reactive actions.
Docker provides a way to package an application and its dependencies into an image, then run that image as a container. In this article, we are going to see the basic Docker concepts and commands using Docker 1.x with Docker Toolbox, which is the new way to run Docker on Windows, replacing the older boot2docker installer. This is Part 1, in upcoming Part 2 we will build our own images with a Dockerfile.
We can start a container in two common ways:
| Approach | Pros | Cons |
|---|---|---|
| Pull a registry image | + Fast first experiment<br>+ Reuses a prepared package | − Depends on image trust<br>− May not match our application |
| Build an application image | + Describes our dependencies<br>+ Repeatable for the team | − Needs a Dockerfile<br>− Build context needs maintenance |
TL;DR Summary
- An image is a packaged, immutable template used to start containers.
- A container is a running instance of an image with an isolated process view.
- Docker Toolbox provides the Docker client and a boot2docker virtual machine on Windows.
docker runcreates and starts a container.- Containers should be replaceable, while durable data belongs in a volume or external service.
- Docker is a packaging and execution tool, not an automatic architecture decision.
Challenges
Environment drift
A web application can depend on a particular runtime, port or configuration file. If those requirements are installed manually on each machine, the setup becomes a collection of undocumented steps. A new team member spends time repairing the environment instead of understanding the domain.
Isolation and lifecycle
A container can be stopped and removed, so anything written only inside its writable layer may be lost. This is a useful property for repeatability, but it is a problem when the team assumes a container is a permanent server. We must separate application state from the container lifecycle.
Tool expectations
Docker 1.x on Windows uses a Linux virtual machine through Docker Toolbox or boot2docker. The commands are familiar, but the environment still has network and filesystem boundaries. We should know where the Docker daemon is running before diagnosing a port or mount issue.
What is an image?
A Docker image is a read-only package containing a filesystem layer and metadata required to start a container.
In simple terms, an image is like a prepared newspaper printing plate. We can use it to produce several copies, but the plate itself is not the running newspaper. The image can come from a registry or be built from a Dockerfile.
What is a container?
A container is a running or stopped instance created from an image.
Simply put, the image is the template and the container is the process using that template. We can start two containers from one image with different names or port mappings. The application should write durable data to an external store or mounted volume.
Why Docker is important?
Docker makes the application boundary more explicit. A developer can pull the same image as the test worker and inspect the same process and port assumptions. It does not remove the need for source control, testing, security or monitoring, because a broken image can still be broken everywhere.
The following diagram depicts an image being used to create multiple containers,

Pull and run a registry image
Steps to Implement:
Follow the following instructions to install Docker Toolbox and run a first container.
-
Install Docker Toolbox for Windows and start the Docker Quickstart Terminal.
-
Create the Docker Toolbox virtual machine with Docker Machine.
docker-machine create --driver virtualbox default -
Set the Docker environment variables for the current terminal.
docker-machine env default -
In Docker Quickstart Terminal, execute the output from the previous command. In Windows Command Prompt, use the
FOR /fform printed by Docker Machine, because the Docker client must know where the Docker daemon is running. -
Just to pulse check, ask Docker for the client and server versions.
docker version -
Search for an image in the Docker registry.
docker search nginx -
Pull an image explicitly before running it.
docker pull nginx -
List the images available in the local cache.
docker images -
Run a container and publish its port.
docker run --name <container-name> -d -p 8080:80 nginx -
List running containers and inspect the published port.
docker ps docker ps -a docker port <container-name> -
Open the Docker host address in a browser.
http://<docker-machine ip>:8080/ -
Find the Docker Machine address and view the container output.
docker-machine ip default docker logs <container-name> -
Run an interactive Ubuntu container to understand the process boundary.
docker run -it ubuntu /bin/bash -
Stop and remove the container after the experiment.
docker stop <container-name> docker rm <container-name> -
Remove an unused image after all containers using it are removed.
docker rmi <image-name>Info: For a quick start, a registry image is fine, but do not use an unreviewed image for production. Review its source, tags, update process and exposed ports.
Containers and data
If a container runs a news article service, its article database should not exist only inside the container. Mount a volume for development data or use an external database service. The container can then be replaced while the data remains available, similar to replacing a newspaper editor’s workstation without losing the archive.
Keep configuration outside the image when it changes by environment. Publish only the ports required by the application and run with the lowest practical privileges. A container is not a security boundary by itself, so the host and image dependencies still need patching.
Image tags and container lifecycle
When we are pulling an image, use a known tag instead of assuming that latest is always the version which was tested. The tag is not a full security guarantee, but it gives the team a repeatable reference. The image should contain the runtime and application package, while the connection string is being supplied by the environment. Keep in mind that Docker containers are Linux based today, so classic ASP.NET on full .NET Framework is not running in them, ASP.NET 5 (now in Release Candidate) with Mono or CoreCLR is the option for .NET developers.
A stopped container is not the same as a deleted container. docker ps -a is showing both states, and this is useful while learning why a process has exited. Check docker logs before starting a new container, because the error message is often telling us whether the command, port or configuration is wrong. Creating many unnamed containers is quickly becoming cleanup work.
The following simple lifecycle is useful,
pull image -> run container -> inspect logs -> stop container -> remove container
It is like a newspaper printing machine. The image is the prepared machine configuration, the container is one running print job, and the output which must survive belongs in an archive outside the temporary job. We should not be storing the only copy of article data inside a disposable container.
Must Do and Don’ts
- Must Do: Record the image name and tag used by a test run.
- Must Do: Publish only the required ports and verify the Docker Machine address.
- Must Do: Keep application data in a volume or external storage.
- Don’t: assume a container is a virtual machine which is having permanent disk state.
- Don’t: use an image from an unknown source for production without reviewing it.
- Be mindful: Docker Toolbox is using a Linux VM, so a Windows path or host address is not automatically the container path.
In upcoming Part 2, we will create a Dockerfile and build an image for an application rather than only pulling a registry image. Before doing that, make sure the team is understanding the image and container lifecycle, otherwise the Dockerfile is only hiding the same environment confusion in a new file.
Wrap up
In this article, we have looked at images, containers, Docker Toolbox, Docker Machine, the Docker host address and the basic Docker 1.x commands. I hope this article provided you some insights into getting started with Docker. In the next article, I will walk you through Dockerfile and building our own images in Part 2.
Related Posts
How to build a Docker image for an ASP.NET Core application?
Building a Docker image for ASP.NET Core explained through Dockerfiles, SDK and runtime images, build commands, containers, configuration and deployment practices.
Getting started with Docker - Part 2
Docker Part 2 explains volumes, user-defined networks and Docker Compose through manual commands, multi-container communication and repeatable local environments for practical guidance.
How to automate releases with VSTS Release Management?
VSTS Release Management explained through release definitions, environments, approvals, variables, deployment slots, smoke tests and automated ASP.NET deployments for practical guidance.