Getting Started With Docker

Being an IT contractor, I usually find myself setting up a clients environment to get their project to work locally. As these are setup by individuals, there is a lack of common practice to be able to get setup quickly and end up having to put the hot fixes in place that have been in place for years.

Initially I looked towards Docker as a way to create identical environments between Windows and Mac. Once I understood the core concept of Docker I realised how useful it could be in any project.

Once the Docker configuration for a project is setup, a new user could have a local container setup, ready to go from 2 command lines.

Below is my first attempt at creating a Docker configuration for a simple Angular project.

Docker

Layered File System

  • Docker is like a cake with multiple layers
  • Writable file layer within container can be lost

Volumes

  • A directory associated to the container.
  • Know as data volume
  • These are persistent
  • Alias to folder in docker host

docker-machine

docker-machine ls
docker-machine start [machine-name]
docker-machine stop [machine-name]
docker-machine env [machine-name]
docker-machine ip [machine-name]
docker-machine status [machine-name]

images

docker pull [image-name]
docker images
docker rmi [image-id]

container

docker run [image-name]
docker ps -a
docker rm [container-id]
docker rm -v [container-id]
Code Explanation
-v Remove volume associated with container

volume

docker run -p 8080:3000 -v /var/www/ node
docker inspect [container-name]
docker run -p 8080:3000 -v $(pwd):/var/www/ node
docker run -p 8080:3000 -v $(pwd):/var/www/ node
docker run -p 8080:3000 -v $(pwd):/var/www/ -w "/var/www/" node npm start
docker run -i -t -p 8080:500 -v $(pwd):/app -w "/app" microsoft/aspnet:1.0.0-rc1-update1-coreclr /bin/bash

NOTES

Code Explanation
-p Port
$(pwd) Current working directory on host
-w Working directory on host
-i Interactive mode
-t Putty
/bin/bash Bash script on VM

The Project

References

Author image
IT guy trying to break the IT stereotype, whilst being addicted to IT stereotypical things.