[英]docker-compose of Nginx image doesn't work when the docker-compose.yml file is moved
Hello, I have project named time_manager that contains a folder named theme_02 .您好,我有一个名为time_manager 的项目,其中包含一个名为theme_02的文件夹。
In the theme_02 project folder, I have a docker-compose.yml
, a Dockerfile
, and all the source code of my Vue project.在theme_02项目文件夹中,我有一个
docker-compose.yml
、一个Dockerfile
以及我的Vue项目的所有源代码。
-time_manager
-theme_02
-Dockerfile
-docker-compose.yml
-etc..
The Dockerfile
: Dockerfile
:
FROM node:latest as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install --prefer-offline --no-audit
COPY ./ .
RUN npm run build
FROM nginx as production-stage
RUN mkdir /app
COPY --from=build-stage /app/dist /app
COPY nginx.conf /etc/nginx/nginx.conf
When I build the docker image with docker build -t vue_front .
当我使用
docker build -t vue_front .
and run the docker container with docker run -it -p 8080:80 vue_front
.并使用
docker run -it -p 8080:80 vue_front
。 it works fine, I can see my Node project它工作正常,我可以看到我的Node项目
My docker-compose.yml
file is:我
docker-compose.yml
文件是:
version: '3.6'
services:
vue_front:
build:
./.
ports:
- "8080:80"
If I use the command docker-compose up -d
, it also works perfectly, my Node project is loading correctly.如果我使用命令
docker-compose up -d
,它也可以完美运行,我的Node项目加载正确。
When I try to move the docker-compose.yml
inside the time_manager , such as:当我尝试在
docker-compose.yml
移动docker-compose.yml
compose.yml 时,例如:
-time_manager
-docker-compose.yml
-theme_02
-Dockerfile
-etc..
I don't forget to update the docker-compose.yml
file:我不会忘记更新
docker-compose.yml
文件:
version: '3.6'
services:
vue_front:
build:
./theme_02
ports:
- "8080:80"
I rebuild the docker images, and runs it, there is no error.我重建 docker 镜像并运行它,没有错误。
But when I go http://localhost:8080
, the page doesn't load.但是当我访问
http://localhost:8080
,页面不会加载。 It seems that moving the docker-compose.yml
file up, create an error, which is strange since I did that for other projects and it worked fine.似乎将
docker-compose.yml
文件向上移动,会产生一个错误,这很奇怪,因为我为其他项目这样做了并且效果很好。
You may have to specify the build.context
field in the docker-compose definition and reference the Dockerfile (using build.dockerfile
field) with the relative path from context
folder.您可能必须在
build.context
-compose 定义中指定build.context
字段,并使用context
文件夹中的相对路径引用 Dockerfile(使用build.dockerfile
字段)。
See: https://docs.docker.com/compose/compose-file/#build请参阅: https : //docs.docker.com/compose/compose-file/#build
Your docker-compose.yml
should look like this :您
docker-compose.yml
应如下所示:
version: '3.6'
services:
vue_front:
build:
context: ./theme_02
dockerfile: Dockerfile #optional
ports:
- "8080:80"
Your docker-compose
file is incorrect.您的
docker-compose
文件不正确。 The build
property should either be a string
or an object
. build
属性应该是一个string
或一个object
。 You are providing neither and it is probably defaulting to the current directory for a build context.您既没有提供,也可能默认为构建上下文的当前目录。
Change to as follows改为如下
version: '3.6'
services:
vue_front:
build: ./theme_02
ports:
- "8080:80"
See documentation for reference https://docs.docker.com/compose/compose-file/#build请参阅文档以供参考https://docs.docker.com/compose/compose-file/#build
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.