我有一个带有DockerFile的Java项目,如下所示:
FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} shape-shop-backend.jar
ENTRYPOINT ["java","-jar","/shape-shop-backend.jar"]
如果我这样运行docker:
C:\dev\shape-shop>docker build -t testtest:1.0
它可以完美地构建图像。
我假设“ gcloud构建提交”的工作方式相同。我在Google云上有一个名为 whataboutanewproject 的项目,因此我在同一目录中运行以下命令:
C:\dev\shape-shop>gcloud builds submit --tag gcr.io/whataboutanewproject/shapeshop
但是我得到这个错误:
Digest: sha256:94792824df2df33402f201713f932b58cb9de94a0cd524164a0f2283343547b3
Status: Downloaded newer image for openjdk:8-jdk-alpine
---> a3562aa0b991
Step 2/6 : RUN addgroup -S spring && adduser -S spring -G spring
---> Running in 36cf2156a797
Removing intermediate container 36cf2156a797
---> 7320b32f6fe1
Step 3/6 : USER spring:spring
---> Running in f439aa9ca30e
Removing intermediate container f439aa9ca30e
---> 67f952c7bc2a
Step 4/6 : ARG JAR_FILE=target/*.jar
---> Running in 0bcfbf5f3b79
Removing intermediate container 0bcfbf5f3b79
---> 7519fa3bdc2f
Step 5/6 : COPY ${JAR_FILE} shape-shop-backend.jar
COPY failed: no source files were specified
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ERROR: (gcloud.builds.submit) build d3704337-88de-4dda-a120-ebd2a01ee8c9 completed with status "FAILURE"
C:\dev\shape-shop>
为什么不能正确处理DockerFile?
“ gcloud构建提交”甚至可以构建映像吗? website上的文档非常垃圾,以至于我完全不知道“ gcloud build Submit”命令的作用。
答案 0 :(得分:1)
您必须指定源位置。
gcloud builds submit ${PWD} ...
然后将复制${PWD}
(通常使用.
代替)到Cloud Build中的/workspace
(默认)目录,以便继续构建(特别是COPY ${JAR_FILE} ...
。
FROM busybox
ARG JAR_FILE=target/test.txt
COPY ${JAR_FILE} test.txt
ENTRYPOINT ["more","test.txt"]
注意,更好的不将通配符复制到特定文件
并且:
.
├── Dockerfile
└── target
└── test.txt
并且:
docker build --tag=test --file=./Dockerfile .
docker run --interactive --tty test:latest
Hello Freddie!
然后,假设已启用云的GCP项目({PROJECT}
):
gcloud builds submit . --tag=gcr.io/${PROJECT}/test --project=${PROJECT}
docker run --interactive --tty gcr.io/${PROJECT}/test:latest
...
Hello Freddie!
注意
gcloud builds submit
需要.
或${PWD}