英文:
directory structure in Dockerfile
问题
I have a directory and its structure is something like this:
.
├── docker
│ ├── docker-compose.yml
│ └── Dockerfile
├── java-app
│ ├── pom.xml
│ └── src
我想创建一个 Docker 镜像,但不改变结构,但是我遇到了这个错误:
=> [internal] load build context 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [2/5] WORKDIR /app 0.0s
=> ERROR [3/5] COPY java-app/pom.xml /app/ 0.0s
=> ERROR [4/5] COPY java-app/src /app/src 0.0s
------
> [3/5] COPY java-app/pom.xml /app/:
------
------
> [4/5] COPY java-app/src /app/src:
------
Dockerfile:8
--------------------
6 |
7 | # Copy the necessary files to the working directory
8 | >>> COPY java-app/pom.xml /app/
9 | COPY java-app/src /app/src
10 |
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref b1c85d8c-d082-47bf-843c-99a804945668a::o15zbeasfb4ieh2fetvzcczhp4a: "/java-app/pom.xml": not found
这是我的 Dockerfile
# Use a base image with Java 11 installed
FROM eclipse-temurin:11-jdk
# Set the working directory inside the container
WORKDIR /app
# Copy the necessary files to the working directory
COPY ../java-app/pom.xml /app/
COPY ../java-app/src /app/src
# Build the application
RUN ./mvn package -DskipTests
# Expose the port on which the application will run
EXPOSE 8080
# Start the application
CMD ["java", "-jar", "target/your-app.jar"]
我在这里做错了什么?我会感激您的帮助。
英文:
I have a directory and it's structure is something like this:
.
├── docker
│ ├── docker-compose.yml
│ └── Dockerfile
├── java-app
│ ├── pom.xml
│ └── src
I want to create a docker image without changing the structure but I am getting this error:
=> [internal] load build context 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [2/5] WORKDIR /app 0.0s
=> ERROR [3/5] COPY java-app/pom.xml /app/ 0.0s
=> ERROR [4/5] COPY java-app/src /app/src 0.0s
------
> [3/5] COPY java-app/pom.xml /app/:
------
------
> [4/5] COPY java-app/src /app/src:
------
Dockerfile:8
--------------------
6 |
7 | # Copy the necessary files to the working directory
8 | >>> COPY java-app/pom.xml /app/
9 | COPY java-app/src /app/src
10 |
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref b1c85d8c-d082-47bf-843c-99a804945668a::o15zbeasfb4ieh2fetvzcczhp4a: "/java-app/pom.xml": not found
This is my Dockerfile
# Use a base image with Java 11 installed
FROM eclipse-temurin:11-jdk
# Set the working directory inside the container
WORKDIR /app
# Copy the necessary files to the working directory
COPY ../java-app/pom.xml /app/
COPY ../java-app/src /app/src
# Build the application
RUN ./mvn package -DskipTests
# Expose the port on which the application will run
EXPOSE 8080
# Start the application
CMD ["java", "-jar", "target/your-app.jar"]
What am I doing wrong here? I would appreciate some help
答案1
得分: 1
Docker会将上下文文件夹设置为运行命令的文件夹。您可以从Dockerfile外部运行以下命令:
docker build -f docker/Dockerfile .
然后,在Dockerfile中,您可以编辑COPY命令的路径,如下:
COPY java-app/pom.xml /app/
COPY java-app/src /app/src
英文:
Docker will set the context folder with the folder which you run the command. You can run from outside of Dockerfile
docker build -f docker/Dockerfile .
And in the Dockerfile you can edit path 2 line with COPY
COPY java-app/pom.xml /app/
COPY java-app/src /app/src
答案2
得分: 1
从文档中:
> 默认情况下,docker build命令将在构建上下文的根目录查找Dockerfile。 -f、--file选项允许您指定要使用的替代文件的路径。
因此,您可以从Java应用程序目录中使用以下命令:
docker build -f ../docker/Dockerfile .
英文:
From the documentation:
> By default the docker build command will look for a Dockerfile at the root of the build context. The -f, --file, option lets you specify the path to an alternative file to use instead.
so you could, from the java app directory, use:
docker build -f ../docker/Dockerfile .
答案3
得分: 0
Docker将文件集发送到服务器(称为“上下文”)
服务器只能看到这个拷贝。你不能越出它。
移动Docker文件。
英文:
Docker sends the set of files around the docker file to the server (called “context”)
The server sees this copy only. You cannot go outside of it.
Move the docker file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论