Docker: Mern 项目页面未加载
Docker: Mern project page isn't loading
我正在尝试 运行 使用 Docker 工具箱的 MERN 项目,因为我在 Windows 机器上,但我的项目没有 运行。
这是我的项目文件夹结构:
├───api
│ └───Dockerfile
├───ui
│ └───Dockerfile
├───docker-compose.yml
docker-compose.yml
version: '2'
services:
ui:
build: ./ui
ports:
- '3000:3000'
depends_on:
- api
#command: tail -f /dev/null
api:
build: ./api
ports:
- '8080:8080'
depends_on:
- mongo
mongo:
image: mongo
ports:
- '27017:27017'
./ui/Dockerfile
FROM node:8
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package*.json ./
RUN npm install
# Copy app source code
COPY . .
#Expose port and start application
EXPOSE 3000
CMD ["npm", "start"]
./api/Dockerfile
FROM node:8
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package*.json ./
RUN npm install
# Copy app source code
COPY . .
#Expose port and start application
EXPOSE 8080
CMD [ "npm", "start" ]
当我从根目录 运行 docker-compose up --build
时,一切似乎都可以正确编译,但它会以 express-mongo-docker-tutorial_ui_1 exited with code 0
退出
...
...
...
ui_1 |
ui_1 | > ui@0.1.0 start /usr/src/app
ui_1 | > react-scripts start
ui_1 |
ui_1 | ℹ 「wds」: Project is running at http://172.27.0.4/
ui_1 | ℹ 「wds」: webpack output is served from
ui_1 | ℹ 「wds」: Content not from webpack is served from /usr/src/app/public
ui_1 | ℹ 「wds」: 404s will fallback to /
ui_1 | Starting the development server...
ui_1 |
express-mongo-docker-tutorial_ui_1 exited with code 0
docker-machine ip default
打印出 192.168.99.101
所以我转到 192.168.99.101:3000
但我的页面没有加载
如果我这样做 docker ps
我明白了
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd90ffb3323f express-mongo-docker-tutorial_api "docker-entrypoint.s…" 22 minutes ago Up 22 minutes 0.0.0.0:8080->8080/tcp express-mongo-docker-tutorial_api_1
5ed2d070b45f mongo "docker-entrypoint.s…" 22 minutes ago Up 22 minutes 0.0.0.0:27017->27017/tcp express-mongo-docker-tutorial_mongo_1
我尝试了将 command: tail -f /dev/null
添加到我的 docker-compose.yml
文件的解决方案,我确实看到了容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1d54f603fca express-mongo-docker-tutorial_ui "docker-entrypoint.s…" 8 seconds ago Up 7 seconds 0.0.0.0:3000->3000/tcp express-mongo-docker-tutorial_ui_1
321682880d04 express-mongo-docker-tutorial_api "docker-entrypoint.s…" 9 seconds ago Up 8 seconds 0.0.0.0:8080->8080/tcp express-mongo-docker-tutorial_api_1
d8e31d09f8e5 mongo "docker-entrypoint.s…" 10 seconds ago Up 10 seconds 0.0.0.0:27017->27017/tcp express-mongo-docker-tutorial_mongo_1
但是当我转到 192.168.99.101:3000
时,我的页面仍然无法加载。我做错了什么?
我想出来了,我所要做的就是在我的 docker-compose.yml
中添加 tty:true
ui:
build: ./ui
ports:
- '3000:3000'
depends_on:
- api
tty:true #<-----
我正在尝试 运行 使用 Docker 工具箱的 MERN 项目,因为我在 Windows 机器上,但我的项目没有 运行。
这是我的项目文件夹结构:
├───api
│ └───Dockerfile
├───ui
│ └───Dockerfile
├───docker-compose.yml
docker-compose.yml
version: '2'
services:
ui:
build: ./ui
ports:
- '3000:3000'
depends_on:
- api
#command: tail -f /dev/null
api:
build: ./api
ports:
- '8080:8080'
depends_on:
- mongo
mongo:
image: mongo
ports:
- '27017:27017'
./ui/Dockerfile
FROM node:8
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package*.json ./
RUN npm install
# Copy app source code
COPY . .
#Expose port and start application
EXPOSE 3000
CMD ["npm", "start"]
./api/Dockerfile
FROM node:8
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package*.json ./
RUN npm install
# Copy app source code
COPY . .
#Expose port and start application
EXPOSE 8080
CMD [ "npm", "start" ]
当我从根目录 运行 docker-compose up --build
时,一切似乎都可以正确编译,但它会以 express-mongo-docker-tutorial_ui_1 exited with code 0
...
...
...
ui_1 |
ui_1 | > ui@0.1.0 start /usr/src/app
ui_1 | > react-scripts start
ui_1 |
ui_1 | ℹ 「wds」: Project is running at http://172.27.0.4/
ui_1 | ℹ 「wds」: webpack output is served from
ui_1 | ℹ 「wds」: Content not from webpack is served from /usr/src/app/public
ui_1 | ℹ 「wds」: 404s will fallback to /
ui_1 | Starting the development server...
ui_1 |
express-mongo-docker-tutorial_ui_1 exited with code 0
docker-machine ip default
打印出 192.168.99.101
所以我转到 192.168.99.101:3000
但我的页面没有加载
如果我这样做 docker ps
我明白了
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd90ffb3323f express-mongo-docker-tutorial_api "docker-entrypoint.s…" 22 minutes ago Up 22 minutes 0.0.0.0:8080->8080/tcp express-mongo-docker-tutorial_api_1
5ed2d070b45f mongo "docker-entrypoint.s…" 22 minutes ago Up 22 minutes 0.0.0.0:27017->27017/tcp express-mongo-docker-tutorial_mongo_1
我尝试了将 command: tail -f /dev/null
添加到我的 docker-compose.yml
文件的解决方案,我确实看到了容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1d54f603fca express-mongo-docker-tutorial_ui "docker-entrypoint.s…" 8 seconds ago Up 7 seconds 0.0.0.0:3000->3000/tcp express-mongo-docker-tutorial_ui_1
321682880d04 express-mongo-docker-tutorial_api "docker-entrypoint.s…" 9 seconds ago Up 8 seconds 0.0.0.0:8080->8080/tcp express-mongo-docker-tutorial_api_1
d8e31d09f8e5 mongo "docker-entrypoint.s…" 10 seconds ago Up 10 seconds 0.0.0.0:27017->27017/tcp express-mongo-docker-tutorial_mongo_1
但是当我转到 192.168.99.101:3000
时,我的页面仍然无法加载。我做错了什么?
我想出来了,我所要做的就是在我的 docker-compose.yml
tty:true
ui:
build: ./ui
ports:
- '3000:3000'
depends_on:
- api
tty:true #<-----