首页 > 解决方案 > Docker docker-compose 无法访问 Dockerfile 中指定的 jarfile

问题描述

当我运行命令时一切都很好

docker build -f Dockerfile -t my_app_name .
docker run -t my_app_name

但是,如果我尝试使用docker-compose up

我收到错误 app_1 | Error: Unable to access jarfile /D-1.jar

我有一个文件结构为的项目

DockerPlayground
  |_build
      |_libs
         |_D-1.jar
  |_src
      |_main
          |_java
              |_com.DockerPlayground
                  My Code Here
  docker-compose.yml
  Dockerfile

我的 Dockerfile

FROM openjdk:11-jre-slim
COPY build/libs/*.jar D-1.jar
ENTRYPOINT ["java","-jar","/D-1.jar"]

我的 docker-compose.yml

version: '3'
services:
  app:
    build:
      context: ""
      dockerfile: Dockerfile
    ports:
      - "8080:8080" # Forward the exposed port 8080 on the container to port 8080 on the host machine
    restart: always

标签: javaspring-bootdockerjardocker-compose

解决方案


推荐阅读