Follow guides in https://docs.docker.com/get-docker/
Windows: Must enable Hyper-V and Containers Windows features via
- Right click on the Windows button and select ‘Apps and Features’
- Select Programs and Features on the right under related settings.
- Select Turn Windows Features on or off.
- Select Hyper-V and Containers (WSL if needed)
- Click OK.
$ docker version
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,
- A cut-down OS
- A runtime environment (eg Node, MongoDB, Python, etc.)
- Application files
- 3rd party libraries
- Environment variables
Once we have an image, we tell docker to start a container using that image w/ command: $ docker run ...
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
$ mkdir hello-docker # create directory
$ cd hello-docker # move into directory
$ code. # run vs code for editor
Create a new file app.js
console.log("Hello Docker!");
Instructions for deploying this program
Run $ node app.js
→ Write instructions in Dockerfile
Create Dockerfile (Don’t need extension)
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
Testing docker images in docker hub in https://labs.play-with-docker.com/
$ docker pull [name]
$ docker image ls
$ docker run [name]