我有一个主 docker-compose.yml:
version: '3'
services:
recognizer:
container_name: recognizer
build: ./recognizer
hostname: recognizer
restart: always
ports:
- 8084:8084
network_mode: "host"
我的文件夹识别器包含 Dockerfile 和 docker-compose.yml :
Dockerfile:
FROM openjdk:8
RUN mkdir -p /app/
COPY . /app
WORKDIR /app
RUN chmod 777 /app/gradlew
RUN apt-get update && apt-get install -y netcat-traditional
RUN nc -w 2 -v localhost 5432 </dev/null; status=$?; exit $status;
RUN ./gradlew build
CMD ["./gradlew", "run"]
EXPOSE 8084
搬运工-compose.yml :
recognizer:
build:
context: .
ports:
- "8084:8084"
我的文件结构是:
.
├── docker-compose.yml
├── recognizer
│ ├── build
│ ├── build.gradle
│ ├── docker-compose.yml
│ ├── Dockerfile
│ ├── gradle
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle
│ └── src
因此,我需要在localhost
阶段连接到build
。有用。如果我用选项--network=host
构建Docker镜像,那样:
docker build --network=host -t recognizer .
但我不知道如何为docker-compose指定构建选项。
答案 0 :(得分:0)
在 docker-compose.yml 中有一个设置网络的选项,如下所示:
build:
context: ./
dockerfile: Dockerfile
network: host
然后 docker-compose build your-service
将使用主机网络进行构建阶段。
这为我解决了问题