Sbt-native-packager 无法连接到 Docker 守护进程
Sbt-native-packager cannot connect to Docker daemon
这是我使用了一年多但突然停止工作的配置。
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
stage: deploy
image: "hseeberger/scala-sbt:11.0.9.1_1.4.4_2.13.4"
before_script:
- apt-get update
- apt-get install sudo
- apt-get install apt-transport-https ca-certificates curl software-properties-common -y
- curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
- apt-get update
- apt-get install docker-ce -y
- sudo service docker start
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- sbt docker:publishLocal
GitlabCI报错如下:
[warn] [1] sbt-native-packager wasn't able to identify the docker version. Some features may not be enabled
[warn] sbt-native packager tries to parse the `docker version` output. This can fail if
[warn]
[warn] - the output has changed:
[warn] $ docker version --format '{{.Server.APIVersion}}'
[warn]
[warn] - no `docker` executable is available
[warn] $ which docker
[warn]
[warn] - you have not the required privileges to run `docker`
[warn]
[warn] You can display the parsed docker version in the sbt console with:
[warn]
[warn] sbt:your-project> show dockerApiVersion
[warn]
[warn] As a last resort you could hard code the docker version, but it's not recommended!!
[warn]
[warn] import com.typesafe.sbt.packager.docker.DockerApiVersion
[warn] dockerApiVersion := Some(DockerApiVersion(1, 40))
[warn]
[success] All package validations passed
[error] Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[info] Removing intermediate image(s) (labeled "snp-multi-stage-id=9da90b0c-75e0-4f46-98eb-a17a1998a3b8")
[error] Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[error] Something went wrong while removing multi-stage intermediate image(s)
[error] java.lang.RuntimeException: Nonzero exit value: 1
[error] at com.typesafe.sbt.packager.docker.DockerPlugin$.publishLocalDocker(DockerPlugin.scala:687)
[error] at com.typesafe.sbt.packager.docker.DockerPlugin$.$anonfun$projectSettings(DockerPlugin.scala:266)
[error] at com.typesafe.sbt.packager.docker.DockerPlugin$.$anonfun$projectSettings$adapted(DockerPlugin.scala:258)
[error] at scala.Function1.$anonfun$compose(Function1.scala:49)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219(TypeFunctions.scala:62)
[error] at sbt.std.Transform$$anon.work(Transform.scala:68)
[error] at sbt.Execute.$anonfun$submit(Execute.scala:282)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] at sbt.Execute.work(Execute.scala:291)
[error] at sbt.Execute.$anonfun$submit(Execute.scala:282)
[error] at sbt.ConcurrentRestrictions$$anon.$anonfun$submitValid(ConcurrentRestrictions.scala:265)
[error] at sbt.CompletionService$$anon.call(CompletionService.scala:64)
[error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error] at java.base/java.lang.Thread.run(Thread.java:834)
[error] (Docker / publishLocal) Nonzero exit value: 1
您似乎在尝试 运行 构建映像中的 docker 守护进程 docker 运行.
对于 Linux,您需要确保当前用户(运行ning sbt
)具有 运行 [=25] 的适当权限=] 命令与一些 post-install steps.
也许您可以通过 运行ning sudo sbt docker:publishLocal
来修复您的脚本?
现在更常见的是使用服务为您的构建设置 docker 守护程序:
services:
- docker:dind
看到这个 example on gitlab. There is also a section in the (EE) docs。
我终于通过安装 Sbt 而不是 Docker 解决了这个问题。我现在也在 Gitlab 的 Docker 服务中使用 Docker,这基本上可以帮助我避免上述问题。
image: docker:19.03.12
services:
- mysql:latest
- docker:19.03.12-dind
docker:image:
needs: ["test"]
stage: deploy
before_script:
- apk update
- apk --no-cache add openjdk11
- export PATH="/usr/local/sbt/bin:$PATH"
- apk update && apk add bash ca-certificates wget tar && mkdir -p "/usr/local/sbt" && wget -qO - --no-check-certificate "https://github.com/sbt/sbt/releases/download/v1.5.5/sbt-1.5.5.tgz" | tar xz -C /usr/local/sbt --strip-components=1 && sbt sbtVersion
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- sbt docker:publishLocal
- docker tag x:latest registry.gitlab.com/x/y:0.1-SNAPSHOT-$(date +%Y-%m-%d-%H-%M)
- docker push registry.gitlab.com/x/y/project-$(date +%Y-%m-%d-%H-%M)
only:
- master
这是我使用了一年多但突然停止工作的配置。
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
stage: deploy
image: "hseeberger/scala-sbt:11.0.9.1_1.4.4_2.13.4"
before_script:
- apt-get update
- apt-get install sudo
- apt-get install apt-transport-https ca-certificates curl software-properties-common -y
- curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
- apt-get update
- apt-get install docker-ce -y
- sudo service docker start
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- sbt docker:publishLocal
GitlabCI报错如下:
[warn] [1] sbt-native-packager wasn't able to identify the docker version. Some features may not be enabled
[warn] sbt-native packager tries to parse the `docker version` output. This can fail if
[warn]
[warn] - the output has changed:
[warn] $ docker version --format '{{.Server.APIVersion}}'
[warn]
[warn] - no `docker` executable is available
[warn] $ which docker
[warn]
[warn] - you have not the required privileges to run `docker`
[warn]
[warn] You can display the parsed docker version in the sbt console with:
[warn]
[warn] sbt:your-project> show dockerApiVersion
[warn]
[warn] As a last resort you could hard code the docker version, but it's not recommended!!
[warn]
[warn] import com.typesafe.sbt.packager.docker.DockerApiVersion
[warn] dockerApiVersion := Some(DockerApiVersion(1, 40))
[warn]
[success] All package validations passed
[error] Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[info] Removing intermediate image(s) (labeled "snp-multi-stage-id=9da90b0c-75e0-4f46-98eb-a17a1998a3b8")
[error] Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[error] Something went wrong while removing multi-stage intermediate image(s)
[error] java.lang.RuntimeException: Nonzero exit value: 1
[error] at com.typesafe.sbt.packager.docker.DockerPlugin$.publishLocalDocker(DockerPlugin.scala:687)
[error] at com.typesafe.sbt.packager.docker.DockerPlugin$.$anonfun$projectSettings(DockerPlugin.scala:266)
[error] at com.typesafe.sbt.packager.docker.DockerPlugin$.$anonfun$projectSettings$adapted(DockerPlugin.scala:258)
[error] at scala.Function1.$anonfun$compose(Function1.scala:49)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219(TypeFunctions.scala:62)
[error] at sbt.std.Transform$$anon.work(Transform.scala:68)
[error] at sbt.Execute.$anonfun$submit(Execute.scala:282)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] at sbt.Execute.work(Execute.scala:291)
[error] at sbt.Execute.$anonfun$submit(Execute.scala:282)
[error] at sbt.ConcurrentRestrictions$$anon.$anonfun$submitValid(ConcurrentRestrictions.scala:265)
[error] at sbt.CompletionService$$anon.call(CompletionService.scala:64)
[error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error] at java.base/java.lang.Thread.run(Thread.java:834)
[error] (Docker / publishLocal) Nonzero exit value: 1
您似乎在尝试 运行 构建映像中的 docker 守护进程 docker 运行.
对于 Linux,您需要确保当前用户(运行ning sbt
)具有 运行 [=25] 的适当权限=] 命令与一些 post-install steps.
也许您可以通过 运行ning sudo sbt docker:publishLocal
来修复您的脚本?
现在更常见的是使用服务为您的构建设置 docker 守护程序:
services:
- docker:dind
看到这个 example on gitlab. There is also a section in the (EE) docs。
我终于通过安装 Sbt 而不是 Docker 解决了这个问题。我现在也在 Gitlab 的 Docker 服务中使用 Docker,这基本上可以帮助我避免上述问题。
image: docker:19.03.12
services:
- mysql:latest
- docker:19.03.12-dind
docker:image:
needs: ["test"]
stage: deploy
before_script:
- apk update
- apk --no-cache add openjdk11
- export PATH="/usr/local/sbt/bin:$PATH"
- apk update && apk add bash ca-certificates wget tar && mkdir -p "/usr/local/sbt" && wget -qO - --no-check-certificate "https://github.com/sbt/sbt/releases/download/v1.5.5/sbt-1.5.5.tgz" | tar xz -C /usr/local/sbt --strip-components=1 && sbt sbtVersion
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- sbt docker:publishLocal
- docker tag x:latest registry.gitlab.com/x/y:0.1-SNAPSHOT-$(date +%Y-%m-%d-%H-%M)
- docker push registry.gitlab.com/x/y/project-$(date +%Y-%m-%d-%H-%M)
only:
- master