What is Docker

Docker is a software platform that allows developer to build, test and deploy application quickly. In the nut shell, docker can deploy the developer application into different running environment. Let's say, someone with a "Node" with a different version can still run the application as the same as the developer have.

Docker compose of three main parts:

  • Docker files (Blue print of the Image. We need to modify this file to export our application)
  • Image (Environment, eg. Ubuntu, Node version, etc.)
  • Container (The package.json file, which contain all the library and the depandency.)

Why use Docker

Docker enable the developer to develop at the local environment and ship easily.

How

First, download the Docker destop app here, which have both Mac and Window Version. Docker destop app contain a GUI, which can be more user-friendly for begineers.

Second, if using Visual Studio code, you can also install the docker extension, and run it internally with VS code terminal.

Common commands for Docker

terminal
docker ps
docker build
docker run
docker pull
docker tag
docker push

Writing an docker file

FROM
used to specify Docker Image Name and start the build process

#specify a Base Image

FROM ubuntu:latest
FROM node:12

Maintainer
used to about the person who creates the Docker Image

MAINTAINER support@fosstechnix.com

CMD
used to execute a command in Running container, There should be one CMD in a Dockerfile.

# To run apache2 in foreground

CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]

RUN
used to execute any commands on top of current Docker Image.

RUN executes the command when you are building Image.

FROM ubuntu:latest
MAINTAINER support@fosstechnix.com
RUN apt-get update
RUN apt-get install -y apache2

EXPOSE
used to specify Network port for Docker container

# To Expose port 80 of Docker container

EXPOSE 80
EXPOSE 8080/tcp

ENV
used to set Environment Variables with key and value.

FROM node:12
ENV workdirectory /usr/node

VOLUME
used to create or mount volume to docker container.

FROM node:12
RUN mkdir /node
WORKDIR /node
RUN echo "Welcome to Node.js" > node
VOLUME /node