# Use git-credentials in a docker container

**URL:** <https://forum.buildkite.community/t/use-git-credentials-in-a-docker-container/3137>\
**Category:** General\
**Created:** [July 25, 2023, 8:53am UTC](https://forum.buildkite.community/t/use-git-credentials-in-a-docker-container/3137 "2023-07-25T08:53:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cam.allen](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@cam.allen](https://forum.buildkite.community/u/cam.allen)\
**Post date:** [July 25, 2023, 8:53am UTC](https://forum.buildkite.community/t/use-git-credentials-in-a-docker-container/3137/1 "2023-07-25T08:53:17Z")

</div>

I’m trying to do git operations inside a docker container (via compose) but the git system can’t authenticate and hangs as outlined in [Running `git fetch --shallow-since` to fetch commit author log causes hang on Buildkite runners · Issue #212 · KnapsackPro/knapsack\_pro-ruby · GitHub](https://github.com/KnapsackPro/knapsack_pro-ruby/issues/212#issue-1815180023)

It looks like the git credential may be exposed via an ENV var as outlined at [how do you use git-credentials inside a Dockerfile? · Issue #58 · buildkite/elastic-ci-stack-s3-secrets-hooks · GitHub](https://github.com/buildkite/elastic-ci-stack-s3-secrets-hooks/issues/58) but how does one use that correctly to do git operations on the pipeline repo from within the docker container.

Your help is appreciated :)

---

<div class="post-metadata">

**Author:** ![jeremy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/jeremy/32/1040_2.png) [@jeremy](https://forum.buildkite.community/u/jeremy)\
**Post date:** [July 25, 2023, 11:07pm UTC](https://forum.buildkite.community/t/use-git-credentials-in-a-docker-container/3137/2 "2023-07-25T23:07:13Z")

</div>

Hi @cam.allen 👋

Welcome to the community!

This is a great question. You’re correct in that the credential.helper is stored as an environment variable `GIT_CONFIG_PARAMETERS` in the job environment. It may be as simple as ensuring that environment variable is properly passed into the container. If you are using the [docker-compose plugin](https://github.com/buildkite-plugins/docker-compose-buildkite-plugin#pipeline-variables), you can set the `propagate-environment` option on the plugin config to true, and this should propagate the variables set in the job environment into the container.

If that still isn’t working, it may be helpful for us to have a look at some example builds. If you’d like us to take a look at those builds, you can reach out to [support@buildkite.com](mailto:support@buildkite.com) and we’ll be happy to continue troubleshooting there as well!

I’m also curious - why are you needing to perform git operations within the container? Are you not able to perform those operations outside the container in the job environment, and then mount the directories into the container?

---

<div class="post-metadata">

**Author:** ![cam.allen](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@cam.allen](https://forum.buildkite.community/u/cam.allen)\
**Post date:** [July 25, 2023, 11:25pm UTC](https://forum.buildkite.community/t/use-git-credentials-in-a-docker-container/3137/3 "2023-07-25T23:25:09Z")

</div>

Thanks for the prompt response - I have already set the `propagate-environment: true` compose plugin setting while testing previously.

Re the git operations - the issue is with a dependency that runs in our test CI suite as linked in the original post, [Running `git fetch --shallow-since` to fetch commit author log causes hang on Buildkite runners · Issue #212 · KnapsackPro/knapsack\_pro-ruby · GitHub](https://github.com/KnapsackPro/knapsack_pro-ruby/issues/212#issue-1815180023). That code wants to build a list of authors when it’s running inside the container and while it determines how to split the CI test runs out across parallel nodes, and I can’t control that code behaviour sadly.

I’ll email support with the specific builds I have that behaviour on to help debug.
