Giter Club home page Giter Club logo

docker-refresher's Introduction

Setup Docker file

+Dockerfile

FROM node:14.17.6-alpine
RUN addgroup myapp && adduser -S -G myapp user_app // -s: system user, -g:group
USER user_app
WORKDIR /app
RUN mkdir app_data // for volumes
COPY . . // copy all cur_dir to work_dir
ADD api.zip . // add can extract zip files
ADD http://bootstrap4.min.css . // add the file from url
RUN npm install
ENV token=12345678
EXPOSE 9999 // container port
CMD npm start

Setup Docker compose

version: "3.8" // as per docker engine version
services:
    frontend:                   // can be any name
        build: ./frontend       // build image point to dockerfile
        context: my_app
        dockerfile: Dockerfile.dev
        ports:
            -3000:3000
    backend:
        build: ./backend
        ports:
            -3000:3000
        environment: 
            DB_URL: mongodb://db/my_app_volume
    database:
        image: mongo:4.0-xenial // pull image from doc hub
        ports:
            -27017:27017
        volumes:
            - my_app_volume:/data/db

volumes:
  my_app_volume:

Commands

Image:
$ docker images
$ docker image ls
$ docker image rm imageid/imagename (&) --force / -f
$ docker image prune // remove all <none> or dangling image
$ docker build -t image_app_name:tag_name . // . -> Dockerfile directory
$ docker image imageid/imagename:tag_name imageid/imagename:new_tage_name

Container:
$ docker ps (or) -a
$ docker container prune // remove all stopped container
$ docker run imageid/image_app_name // run create container
$ docker run -it imageid/image_app_name sh // sh (or) bash
$ docker run -it -u root imageid/image_app_name sh // as a user
$ docker run -d imageid/image_app_name // detach mode
$ docker run -p 8080:3000 imageid/image_app_name // local_port:container_port
$ docker run -p 8080:3000 -v $(pwd):/app imageid/image_app_name // refresh on dev changes
$ docker exec -it container_id sh // run commands without exiting container
$ docker start container_id // start on existing container
$ docker start -i container_id // intractive
$ docker cp container_id:app/app_data .
$ docker kill container_id
$ docker stop container_id
$ docker logs -f container_id // -f logs the changes

Volume:
$ docker volume create mydata
$ docker volume inspect mydata
$ docker run -d -p 8080:3000 -v mydata:app/app_data imageid/image_app_name


Compose:
$ docker-compose up
$ docker-compose up --no-cache
$ docker-compose ps -a
$ docker-compose down

Image from DockerHub:
$ docker run ubuntu
$ docker run -it ubuntu

Docker template

Angular

React

Abbr

-t:     tag
-a:     all -> shows killed/exited
-d:     detach mode
-it:    Interactive mode
-p:     port
-f:     follow
-u:     user

Misc

RUN: During build of the image

CMD: During execution of the image

EXEC: Execute on the running container

docker run cn // new container

docker start cn // run exisiting container

Increase performance:

copy . . is special instruction, docker will not know if there is any file change, which cause docker to rebuild all the layers after this command. NPM install will run each time which cause it to be slow.

COPY . .
RUN npm install

Solution:

if package.json is same then docker will take npm install from cache which makes it fast

COPY package*.json . 
RUN npm install
COPY . .

Docker compose version https://docs.docker.com/compose/compose-file/

Linux basic

$ ls (or) -l (or) -a (or) -la
$ ls | grep file1
$ cd app/test
$ cd ../
$ pwd // present working directory
$ touch file.txt // create file
$ mkdir foldername
$ mv file.txt foldername
$ rm file.txt (file*, *.txt)
$ rm -r foldername
$ printenv
$ printenv token

# nano
$ nano file.txt // create nano text file
$ cat file.txt // view
$ more file.txt // view
$ less file.txt // view 
$ cat file.txt file1.txt // copy file to file1
$ cat file.txt file1.txt > files.txt // concat all to files
$ ls -l > list.txt // > copy, >> append

docker-refresher's People

Watchers

Sajith avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.