我正在尝试在docker容器中运行我的react应用程序。我使用Docker Toolbox是因为我有Windows 10 Home。当我使用命令“ docker run -p 8080:8080 $ {image_id}”运行映像时,除我无法访问端口192.168.99.104:8080之外,其他一切正常。
当我尝试在浏览器中访问此端口时,该端口未连接。我尝试仅通过192.168.99.104访问它,并进入VirtualBox中的默认虚拟机以更改为端口映射。这些选项均无效。容器暴露的端口表明它正在0.0.0.0.8080-> 8080 / tcp上运行,因此我假设我需要转到192.168.99.104:8080。
当我打印应用程序的输出时,我也没有收到错误。该应用的输出为
> bhm-slideshow@0.1.0 start /usr/src/app
> npm-run-all -p watch-css start-js
> bhm-slideshow@0.1.0 watch-css /usr/src/app
> npm run build-css && node-sass-chokidar --include-path ./node_modules src/ -o src/ --watch --recursive
> bhm-slideshow@0.1.0 start-js /usr/src/app
> react-scripts start
> bhm-slideshow@0.1.0 build-css /usr/src/app
> node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/
> Rendering Complete, saving .css file...
> Wrote CSS to /usr/src/app/src/App.css
> Wrote 1 CSS files to /usr/src/app/src/
> => changed: /usr/src/app/src/App.scss
> Rendering Complete, saving .css file...
> Wrote CSS to /usr/src/app/src/App.css
> ℹ 「wds」: Project is running at http://172.17.0.2/
> ℹ 「wds」: webpack output is served from
> ℹ 「wds」: Content not from webpack is served from /usr/src/app/public
> ℹ 「wds」: 404s will fallback to /
> Starting the development server...
> Compiled with warnings.
这是我的Dockerfile
#base image
FROM node:10
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package*.json ./
RUN npm install
# bundle app's source code inside the Docker image, use COPY instruction
COPY . .
#define commands you want to run
CMD ["npm", "run", "start"]