Hi folks , I'm setting up Pants in GitLab CI for b...
# general
e
Hi folks , I'm setting up Pants in GitLab CI for building/pushing Docker images with DinD but hitting some roadblocks. Anyone here managed to integrate Pants with DinD in CI, especially around Docker config? Would appreciate any tips or pointers on best practices and common pitfalls. Thanks!
14:54:57.71 [DEBUG] computed 1 nodes in 0.323865 seconds. there are 1822 total nodes.
`364145457.71 [DEBUG] Canceled: Finding the
tar
binary - environment:linux_docker`
36514:54:57.71 [ERROR] 1 Exception encountered:
366Engine traceback:
367  in select
368    ..
369  in pants.core.goals.package.package_asset
`370
package
goal`
371Traceback (most recent call last):
372  File "/root/.cache/nce/f60c448851c3b3112b179a56f168ee90d8597297cfc45d3ca7178c6715f6cba8/bindings/venvs/2.19.0/lib/python3.9/site-packages/pants/core/goals/package.py", line 165, in package_asset
373    packages = await MultiGet(
374  File "/root/.cache/nce/f60c448851c3b3112b179a56f168ee90d8597297cfc45d3ca7178c6715f6cba8/bindings/venvs/2.19.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 374, in MultiGet
375    return await _MultiGet(tuple(__arg0))
376  File "/root/.cache/nce/f60c448851c3b3112b179a56f168ee90d8597297cfc45d3ca7178c6715f6cba8/bindings/venvs/2.19.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 172, in __await__
377    result = yield self.gets
378native_engine.IntrinsicError: Failed to obtain version from local Docker: error trying to connect: No such file or directory (os error 2)
379
n
Yes - have you allowed
DOCKER_HOST
to be passed through to Pants? https://www.pantsbuild.org/2.18/docs/docker#docker-configuration
e
Copy code
[docker]
build_args = ["USER", "HOME", "PATH", "GIT_COMMIT_SHA"]
tools = ["docker",]
env_vars = [
  "DOCKER_HOST=<tcp://docker:2376>"
]
no luck same error ^_^
I suspect that the issue stems from the pants system attempting to locate the Docker socket at
/var/run/docker.sock
. However, starting with Docker 19.03 and subsequent versions, the Docker daemon connection is managed automatically. This means there's no longer a requirement to mount the Docker socket into the client. i can run native docker cmd in same job like
docker info , docker ps
c
I use GitLal, docker-in-docker, and Pants
e
Could you share some details about your setup?
as i know docker:dind is based on alpine & Alpine is not yet supported by pants
c
We run use self managed amd64 and arm64 runners in k8s with docker-in-docker enabled. If you add
docker info
to the job before doing anything with Pants, does that work?
e
yes it works
i am planing to do that too
c
`364145457.71 [DEBUG] Canceled: Finding the
tar
binary - environment:linux_docker` Are you using environments?
e
yes
Copy code
[environments-preview.names]
linux_docker = "//:python"
c
ah, Environments I am not using. If you search for your error message you will see a few different threads. Perhaps the issue is the value of
DOCKER_HOST
or https://github.com/pantsbuild/pants/issues/18915
🙏 1
(Some threads report success, so I'm not sure the issue is a blocker.)
e
yes i confirm that the issue comes from this option
thank you so much!
n
I think I've found a workaround for Environments breaking the DOCKER_HOST setting for docker builds. Added to https://github.com/pantsbuild/pants/issues/18915
a
Hi Guys, Sorry to follow up on an older thread, but has there been any progress on this issue? I am new to pants, and we have a gitHub-ci setup where the build is failing with the following error:
Copy code
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock
n
@adventurous-pillow-38958 - no progress I'm aware of. You need to make sure
DOCKER_HOST
is added to the docker subsystem env vars so that the non-default value for gitlab (apparently
DOCKER_HOST=<tcp://localhost:2375>
) is picked up.
a
I'm also seeing this issue. There isn't much support out there for Gitlab CI/CD. @adventurous-pillow-38958 have you made any progress?
a
Hey @ancient-australia-38408 I got this error in GitHub CI. As a workaround, for repo's using pants we have switched to shell executor, as we faced this error when using the Docker executor *
https://docs.gitlab.com/runner/executors/ https://docs.gitlab.com/runner/executors/shell.html I’m attaching some links here for GitLab CI, regarding changing the executor; I hope this helps.
a
Hey Anandhu, thanks for the response. I did end up solving this a different way so I'll share here. I plan on publishing a Gitlab CI/CD component for pants so stay tuned!
Copy code
# .gitlab-ci.yml

variables:
  PANTS_CONFIG_FILES: "pants.ci.toml"
  DOCKER_HOST: "<tcp://docker:2375>"
  DOCKER_TLS_CERTDIR: ""
Copy code
# pants.ci.toml

[docker]
tools = ["docker-credential-gcloud", "dirname", "readlink", "python3"]
env_vars = ["DOCKER_HOST=<tcp://docker:2375>", "DOCKER_TLS_CERTDIR=''"]
🙌 1
s
Hello everyone, I'm encountering a similar issue while using a self-hosted GitHub runner with Docker-in-Docker. Unfortunately, the suggested solution hasn't resolved my problem. 🤔 Here's a snippet from my
pants.ci.toml
file:
Copy code
[docker]
env_vars = ["DOCKER_HOST=unix:///home/runner/var/run/docker.sock"]
However, the
pants package
command is failing with the following error:
Copy code
2025-05-24T21:55:51.7662147Z Engine traceback:
2025-05-24T21:55:51.7662412Z   in `package` goal
2025-05-24T21:55:51.7662568Z
2025-05-24T21:55:51.7662949Z ProcessExecutionFailure: Process 'Building docker image docker-dev:latest' failed with exit code 1.
2025-05-24T21:55:51.7663528Z stdout:
2025-05-24T21:55:51.7663653Z
2025-05-24T21:55:51.7663763Z stderr:
2025-05-24T21:55:51.7664221Z ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Interestingly, I don't see any reference to my custom settings in the logs. I expected
DOCKER_HOST
to be mentioned in the environment variables under:
Copy code
spawned local process as Some(18479) for Process { argv: ["/usr/bin/docker", "buildx", "build", "--output=type=docker", "--pull=False", "--tag", "docker-dev:latest", "--file", "src/python/apps/ml_gateway/Dockerfile.docker-dev", "."], env: {"PATH": "/tmp/pants-sandbox-HrsgbT/_binary_shims_8f03118fb0b8f813fc0212ed7e946ef3cc99a30a46e3e2069b4fad2f63eb3882", "__UPSTREAM_IMAGE_IDS": ""}, ... execution_environment: ProcessExecutionEnvironment { name: Some("local_linux"), platform: Linux_x86_64, strategy: Local }, remote_cache_speculation_delay: 0ns, attempt: 0 }
Any guidance on how to further investigate this issue would be greatly appreciated! Thank you!