Docker Tutorial


Table of Contents:

  1. Basic Concept of Images and Containers
  2. Docker Setup
  3. Developing Fullstack WebApp With Node-js
  4. Writing Dockerfile
  5. Running Docker Image
  6. Push to Docker-hub

1. Basic concepts of docker - Containers and Images

2. Setting up Docker


sudo apt-get update
		
sudo apt-get install docker.io 
 

$ docker version

3. Node Web App

cd node

npm install

node app.js

4. Writing Dockerfile

nano dockerfile

		or  ``` touch dockerfile```

FROM node:10-alpine

RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app

WORKDIR /home/node/app

COPY package*.json ./

USER node

RUN npm install

COPY --chown=node:node . .

5. Running Up the docker image

$ docker build -t your_dockerhub_username/nodejs-image-demo .

$ docker images

6 Pushing Image To Dockerhub

$ docker login -u your_dockerhub_username

$ docker push your_dockerhub_username/nodejs-image-demo

$ docker stop e50ad27074a7

$ docker images -a

$ docker system prune -a

$ docker pull your_dockerhub_username/nodejs-image-demo

$ docker images

$ docker run --name nodejs-image-demo -p 80:8080 -d your_dockerhub_username/nodejs-image-demo