我正在使用https://github.com/bmuschko/gradle-docker-plugin从gradle连接到docker。我有以下任务在Windows上创建容器:
task "docker-container-create"(type: DockerCreateContainer) {
description = "Create Docker container"
group "${dockerGroup}-container"
ext {
dockerTag = project.dockerTag
}
targetImageId { "${dockerRepository}:${project.dockerTag}" as String }
delegate.containerName = containerName
portBindings = ["80:${project.dockerExposedPort}"]
env = ["GRAILS_ENV=development"]
cmd = ["--app.dockerContainerName=${containerName}"]
if(!new File("${project.projectDir}/data").exists()) new File("${project.projectDir}/data").mkdirs()
binds [
("${project.projectDir}/data" as String):'/app/data',
("${project.projectDir}/src/main/config/" as String):'/app/config',
]
}
但是这失败并出现以下错误:
{"message":"invalid volume specification: '/host_mnt/c/Users/**/parts/data:rw'"}
我正在运行Docker版本17.12.0-ce-win47 (15139)-stable
答案 0 :(得分:0)
显然,应按照此版本的发行说明中所述的//C/<folder>
格式定义Windows挂载点:
Fix Mount compatibility when mounting drives with `-v //c/...`, now mounted in /host_mnt/c in the LinuxKit VM. Fixes [docker/for-win#1509](https://github.com/docker/for-win/issues/1509), [docker/for-win#1516](https://github.com/docker/for-win/issues/1516),
我在gradle构建文件中创建了一个小帮助程序实用程序:
def volumes = {volumes -> volumes.collectEntries{k,v ->
if(k.contains('\\')){
k = "//${k.replaceAll('\\\\','/')}"
k = k.replaceAll(':','')
}
[(k):v]
}}
所以配置现在是:
task "docker-container-create"(type: DockerCreateContainer) {
description = "Create Docker container"
group "${dockerGroup}-container"
ext {
dockerTag = project.dockerTag
}
targetImageId { "${dockerRepository}:${project.dockerTag}" as String }
delegate.containerName = containerName
portBindings = ["80:${project.dockerExposedPort}"]
env = ["GRAILS_ENV=development"]
cmd = ["--app.dockerContainerName=${containerName}"]
if(!new File("${project.projectDir}/data").exists()) new File("${project.projectDir}/data").mkdirs()
def volumes = {volumes -> volumes.collectEntries{k,v ->
if(k.contains('\\')){
k = "//${k.replaceAll('\\\\','/')}"
k = k.replaceAll(':','')
}
[(k):v]
}}
binds = volumes([
("${project.projectDir}/data" as String):'/app/data',
("${project.projectDir}/src/main/config/" as String):'/app/config',
])
}
这很有效。