我正在帮助我的团队迁移我们在Java 8上运行的基于tomcat的应用程序。应用程序正在使用docker- composition -up,该应用程序正在使用docker-compose。Yaml文件在项目内部构建几个依赖项,这是docker-compose的高级结构。yaml文件:
version: "3.7"
services:
# Local database setup using MySQL x.x.x
db-app:
build: ./appRoot/database
hostname: "somehostname"
environment:
someEnvVar1: x
someEnvVar2: y
ports:
- "port1:port2"
command: <some data initiation script run>
# service setup block
# run the awesome service inside a docker container
service-app:
build: ./appRoot/serviceName
hostname: 'someHost'
volumes:
- $HOME/.aws/credentials:/home/tomcat/.aws/credentials
- ./appRoot/serviceName/someSandBoxConfig/someFILE.jks:/someFILE.jks:Z
- ./appRoot/serviceName/datadog:/datadog:rw
ports:
- "someport1:someport1"
- "someport2:someport2"
depends_on:
- mock-app
- db-app
environment:
FLAVOR: "someFlavor"
CATALINA_OPTS: "-Duser.timezone=UTC -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9000"
< other dependency app .....>
现在,在每个依赖的app目录中,都有一个单独的Dockerfile,仅为该应用编写。
对于上面的service-app
,我在目录./appRoot/serviceName/Dockerfile
下有Dockerfile
我要做的是:我创建了一个新的源文本文件称为test.txt
文件坐在旁边的Dockerfile,我希望能够复制这个文件到docker容器从源代码时,构建它。
我已经尝试了以下代码:
RUN mkdir /newDir
COPY test.txt /newDir
RUN ls -lah /newDir
运行dockerComposeUp
命令时,我一直得到以下错误:
#12 [ 7/19] COPY ./test.txt /newDir
#12 sha256:a3641aad21a23a5779d756b3fea8187ef76b7bca991c34b180b826e82ab66e58
#12 ERROR: "/test.txt" not found: not found
------
> [ 7/19] COPY ./test.txt /newDir:
------
failed to compute cache key: "/test.txt" not found: not found
我错过了什么?
好了,经过几个小时的调试,我终于解决了这个问题,事实证明,我们正在定义在gradle.properties
文件中复制文件的规则,我们有一个docker
块,像这样:
docker {
name "awesome-service"
copySpec.into("/")
.from ("./awesome-service") {
include "someconfig/**"
....
}
添加我创建的目录,然后它像一个魅力一样工作.......