Git Product home page Git Product logo

bear-node-docker's Introduction

bear-node-docker

Common tools build docker image for node project development

NPM npm

Install

yarn add -D bear-node-docker

Setting

$ cp ./node_modules/bear-node-docker/config/nginx ./deploy/nginx

in your package.json

{
   "dockerRegistry": "docker.io/imagine10255",
   "scripts": {
     "docker:build": "bear-node-docker docker --dockerfile=./node_modules/bear-node-docker/config/dockerfile/react/Dockerfile",
     "docker:push": "bear-node-docker push"
   }
}

imagine10255 is your dockerhub account

[Options] Custom dockerfile in root type command

# react
$ cp ./node_modules/bear-node-docker/config/dockerfile/react/Dockerfile ./

# nest 
$ cp ./node_modules/bear-node-docker/config/dockerfile/nest/Dockerfile ./ 

package.json

{
    "scripts": {
      "docker:build": "bear-node-docker build --dockerfile=./Dockerfile"
    }
}

[Options] Custom use provider docker registry

package.json

{
   "dockerRegistry": "myDockerProvider.bear.com:8443"
}

[Options] Custom publicUrl

package.json

{
  "scripts": {
    "docker:build": "bear-node-docker build --publicUrl=/recommend  --dockerfile=./Dockerfile"
  }
}

Only packaged into docker image

In some old projects, npm build gets stuck when run inside Docker. In such cases, you can build locally and then only put the build path into the Docker image.

Dockerfile

# And then copy over node_modules, etc from that stage to the smaller base image
FROM nginx:1.19-alpine
COPY build /usr/share/nginx/html
COPY deploy/config-nginx/nginx.conf /etc/nginx/conf.d/default.conf
WORKDIR /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Be aware that .dockerignore should not include the build folder (the default for create-react-app is 'build', while for Vite it's 'dist').

package.json

{
  "scripts": {
      "build": "react-scripts build",
      "docker:build": "yarn build && bear-node-docker build --publicUrl=/recommend  --dockerfile=./Dockerfile"
  }
}

Test

ts-node lib/build-docker/node-run.ts

License

MIT © imagine10255

bear-node-docker's People

Contributors

imagine10255 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.