简体   繁体   English

在 docker-compose.yml 中构建 Dockerfile ,它位于另一条路径中

[英]build Dockerfile inside docker-compose.yml which is in another path

i have springboot application, which is created via initializr and i created Dockerfile like following我有springboot应用程序,它是通过initializr创建的,我创建了Dockerfile,如下所示

FROM adoptopenjdk/openjdk11:alpine-jre
ARG JAR_FILE=target/tender-api.jar
WORKDIR /opt/app
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","app.jar"]

i want to deploy in my ubuntu server.我想部署在我的 ubuntu 服务器中。 Because it i created in another path docker-compose.yml因为它是我在另一个路径中创建的 docker-compose.yml

version: '3.8'
services:
  appDB:
    image: postgres:14.1-alpine
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    ports:
      - '5432:5432'
    volumes:
      - db:/var/lib/postgresql/data
  tender:
    image: tender-api:1
    build:
      context: .
      dockerfile: /root/dev/tender-api/Dockerfile
    volumes:
      - /data/tender-api
    ports:
      - "8080:8080"
    depends_on:
      - appDB
volumes:
  db:
    driver: local

And verbose logs are like following详细日志如下

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 32B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/adoptopenjdk/openjdk11:alpine-jre
#3 DONE 0.9s

#4 [internal] load build context
#4 transferring context: 2B done
#4 DONE 0.0s

#5 [3/4] RUN echo target/tender-api.jar
#5 CACHED

#6 [2/4] WORKDIR /opt/app
#6 CACHED

#7 [4/4] COPY target/tender-api.jar app.jar
#7 ERROR: failed to walk /var/lib/docker/tmp/buildkit-mount4259571673/target: lstat /var/lib/docker/tmp/buildkit-mount4259571673/target: no such file or directory

#8 [1/4] FROM docker.io/adoptopenjdk/openjdk11:alpine-jre@sha256:c4e70e7696899eae647575724b77cc71efa8bea35c17b8d58fbb9bb6485af353
#8 resolve docker.io/adoptopenjdk/openjdk11:alpine-jre@sha256:c4e70e7696899eae647575724b77cc71efa8bea35c17b8d58fbb9bb6485af353 done
#8 sha256:c4e70e7696899eae647575724b77cc71efa8bea35c17b8d58fbb9bb6485af353 433B / 433B done
#8 sha256:b565a288907ff71371d4b22e2d1756ecdab0f5df188a8da6e5af388c330b4615 951B / 951B done
#8 sha256:00e2ce5eeb8afe4d1487c5976172e0fcb4258cbf7628836e6476be083e9e3f3e 6.13kB / 6.13kB done
#8 CANCELED
------
 > [4/4] COPY target/tender-api.jar app.jar:
------
failed to solve: failed to compute cache key: failed to walk /var/lib/docker/tmp/buildkit-mount4259571673/target: lstat /var/lib/docker/tmp/buildkit-mount4259571673/target: no such file or directory

now, i can't understand what it is "ERROR: failed to walk...", i just executed docker compose up and afterwards I thought that docker can't create file, because of that i have tried with sudo, Nevertheless it's not working现在,我无法理解它是什么“错误:无法行走......”,我刚刚执行docker compose up ,然后我认为 docker 无法创建文件,因为我已经尝试过使用 sudo,尽管如此不工作

i resolved it and wanted to share with you my solution我解决了,想和你分享我的解决方案

  1. changed Dockerfile like following更改 Dockerfile 如下
#
# Build stage
#
FROM maven:3.6.0-jdk-11-slim AS build
COPY src /app/src
COPY pom.xml /app
RUN mvn -q -f /app/pom.xml clean package -DskipTests 
# without -q you can take limit size problem

#
# Package stage
#
FROM adoptopenjdk/openjdk11:alpine-jre
ARG JAR_FILE=/app/target/tender-api.jar
COPY --from=build  ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

as second, changed context and dockerfile in docker-compose.yml其次,更改 docker-compose.yml 中的上下文和 dockerfile

context: /root/dev/tender-api/
dockerfile:  Dockerfile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM