Install Docker

Follow guides in https://docs.docker.com/get-docker/

Windows: Must enable Hyper-V and Containers Windows features via

  1. Right click on the Windows button and select ‘Apps and Features’
  2. Select Programs and Features on the right under related settings.
  3. Select Turn Windows Features on or off.
  4. Select Hyper-V and Containers (WSL if needed)
  5. Click OK.
$ docker version

Development workflow using Docker

  1. Take application and dockerize it (Make small change so that it can be run by docker) → Add Dockerfile to it.

Dockerfile is a plain text file that includes instructions that docker uses to package up this application into an image. This image contains everything our application needs to run everything such as,

  1. Once we have an image, we tell docker to start a container using that image w/ command: $ docker run ...

  2. Once we have this image, we can push it to a docker registry like docker hub (A storage for docker images that anyone can use)

docker hub - docker is like github - git

  1. Then, we can put it on any machines running docker so that it can have same images w/ development machine which containes a specific version of applications and everything it needs it.

Docker in action

$ mkdir hello-docker # create directory
$ cd hello-docker # move into directory
$ code. # run vs code for editor
FROM node:alpine # Base image (act like inheritance)
COPY . /app # Copy everything in current dir. to new dir. called /app (create dir if not present)
CMD node /app/app.js # execute command
COPY . /app
# If you don't want the prefix for CMD
WORKDIR /app
CMD node app.js

Base images are built and can be found in docker hub: https://hub.docker.com/ Can specify a tag using colon (:)

$ docker build -t hd . # -t tag, . is where docker can find _Dockerfile_
$ docker image ls
$ docker run hd