首页 > 技术文章 > docker 启动 reactjs

panpanwelcome 2020-03-30 16:14 原文

# Dockerfile

# base image
FROM node:latest

LABEL maintainer="B**** Dev <b****dev@****.com>"

# set working directory
WORKDIR /app

EXPOSE 3000
# EXPOSE 80

# add `/app/node_modules/.bin` to $PATH
# ENV NODE_PATH=/app/node_modules
# ENV PATH=/app/node_modules/.bin:$PATH

ENV "LC_ALL"="en_US.UTF-8"
ENV "LANG"="en_US.UTF-8"
ENV "LANGUAGE"="en_US.UTF-8"
# ARG registry=https://registry.npm.taobao.org
# ARG disturl=https://npm.taobao.org/dist
# ARG sass_binary_site=http://cdn.npm.taobao.org/dist/node-sass
# ARG SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install node-sass


# install and cache app dependencies
COPY yarn.lock /app/yarn.lock
COPY package.json /app/package.json
# COPY src ./src
# COPY public ./public
# COPY node_modules ./node_modules

# RUN npm config set registry https://registry.npm.taobao.org
# RUN npm config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass
# RUN npm install
# RUN npm install react-scripts@3.4.1 -g
# RUN npm install react-scripts@3.0.1 -g --silent
# RUN npm install --save next react react-dom

RUN yarn config set registry https://registry.npm.taobao.org 
RUN yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass
RUN yarn
RUN yarn add react-scripts@3.4.1

COPY . /app
RUN yarn install
RUN yarn build

# start app
ENTRYPOINT ["/bin/bash", "/app/run.sh"]
CMD ["start"]
# RUN npm run build

  

PS D:\********.WebSite\jsx> docker build -t website-reactjs:v10 .


PS D:\********.WebSite\jsx>docker run -i -v ${PWD}:/app -v /app/node_modules -p 3001:3000 --rm 805147207dd5

  

 

PS D:\********.WebSite\jsx> docker tag website-reactjs:v10 192.168.33.21:5000/westwin/msap/website-reactjs:v10 

PS D:\********.WebSite\jsx> docker push 192.***.**.**:5000/westwin/msap/website-reactjs:v10 


PS D:\WestWin\Projects\msap\Source\MSAP.WebSite\jsx> docker pull 192.***.**.**:5000/westwin/msap/website-reactjs:v10 

  

 

# run.sh

#!/usr/bin/env bash
set -eo pipefail

case $1 in
  start)
    # The '| cat' is to trick Node that this is an non-TTY terminal
    # then react-scripts won't clear the console.
    yarn start | cat
    ;;
  build)
    yarn build
    ;;
  test)
    yarn test $@
    ;;
  *)
    exec "$@"
    ;;
esac

  

推荐阅读