【问题标题】:Dockerizing react appDockerizing React 应用程序
【发布时间】:2018-06-17 07:45:39
【问题描述】:
The build folder is ready to be deployed.
You may serve it with a static server:

serve -s build

---> b252a9088991
Removing intermediate container cb5c1e2629c9
Step 16/16 : RUN serve -s build
---> Running in c27b54b31108
serve: Running on port 5000

使用 react-app 创建和 dockerized react 应用程序,并在“docker-compose up”命令中获得类似上面的输出 但http://0.0.0.0:5000/http://localhost:5000/ 上没有显示任何内容

version: '3'
services:
web:
   build: .
   image: react-cli
   container_name: react-cli
   volumes:
   - .:/app
   ports:
   - '3000:3000'

在我的 docker-compose.yml 文件上方

FROM scratch
FROM mhart/alpine-node:6.12.0

RUN npm install -g npm --prefix=/usr/local
RUN ln -s -f /usr/local/bin/npm /usr/bin/npm

CMD [ "/bin/sh" ]





ENV NPM_CONFIG_LOGLEVEL warn

RUN npm install -g serve
CMD serve -s build
EXPOSE 3000

COPY package.json package.json
COPY semantic.json semantic.json

COPY npm-shrinkwrap.json npm-shrinkwrap.json
RUN npm install gulp-header --save-dev
RUN npm install --no-optional

COPY . .

RUN npm run build --production

RUN serve -s build

这是我的 Dockerfile

【问题讨论】:

    标签: node.js reactjs docker


    【解决方案1】:

    您很可能没有在主机上公开容器端口。我看不到您的撰写文件的外观,但您可能需要添加

    ports:
      - "5000:5000"
    

    到您在撰写文件中的容器定义。

    【讨论】:

    • 我刚刚包含了我的 docker 文件和 docker compose 文件
    • @shijin 你在你的文件中暴露了 3000 端口,而serve 声称它在 5000 服务。请在你的文件中将 3000 更改为 5000
    • 我在两个文件中都使用了 3000,但仍然使用 5000
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 2020-10-08
    • 2020-06-18
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    相关资源
    最近更新 更多