Configuring access to private repositories
Edit on GitHub
You are browsing a previous version of the document. The latest version is 202212.0.
This document describes how to configure an environment to allow the Docker SDK access private repositories.
In what cases do I need to configure access to private repositories?
You need to configure access to private repositories in the following cases:
- You have a private repository mentioned in
composer.json
:
{
"require": {
"my-repo": "dev-master"
},
"repositories": [
{
"type": "git",
"url": "git@github.com:my-org/my-repo.git"
}
]
}
- Running
docker/sdk up
returns an error similar to the following:
Cloning into '/data/vendor/my-org/my-repo'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Configuring an environment to access private repositories
To configure an environment to access private reporitories:
- Add the
.known_hosts
file with the list of domains of VCS services into the project root. Example:
github.com
bitbucket.org
gitlab.my-org.com
- Configure authentication of Composer to VCS services using one of the following options:
- Configuring SSH agent authentication for Composer. We recommend this option for development purposes.
- Configuring the Composer authentication environment variable. We recommend this option for setting up CI/CD pipelines.
Configuring SSH agent authentication for Composer
To configure SSH agent:
- Ensure that
GITHUB_TOKEN
andCOMPOSER_AUTH
environment variables are not set:
unset GITHUB_TOKEN
unset COMPOSER_AUTH
- Prepare SSH agent by adding your private keys:
eval $(ssh-agent)
ssh-add -K ~/.ssh/id_rsa
-
MacOS and Windows: For Docker Desktop to fetch the changes, restart the OS.
-
Re-build the application:
docker/sdk up --build
Configuring the Composer authentication environment variable
To configure the Composer authentication environment variable:
-
Create access tokens in your VCS services.
-
Prepare a
COMPOSER_AUTH
environment variable with the VCS tokens you’ve created in JSON:- GitHub:
{ "github-oauth": { "github.com": "{GITHUB_TOKEN}" } }
- BitBucket:
{ "bitbucket-oauth": { "bitbucket.org": { "consumer-key": "{BITBUCKET_KEY}", "consumer-secret": "{BITBUCKET_SECRET}" } } }
- GitLab
{ "gitlab-token": { "mysprykershop.com": "{GITLAB_TOKEN}" } }
To learn about Composer authentication variables, see COMPOSER_AUTH and Custom token authentication
- Enable the environment variable using one of the following options:
- Export the environment variable taking Bash escaping rules into consideration:
export COMPOSER_AUTH="{\"github-oauth\":{\"github.com\":\"{GITHUB_TOKEN}\"},\"gitlab-oauth\":{\"gitlab.com\":\"{GITLAB_TOKEN}\"},\"bitbucket-oauth\":{\"bitbucket.org\": {\"consumer-key\": \"{BITBUCKET_KEY}\", \"consumer-secret\": \"{BITBUCKET_SECRET}\"}}}"
- Add the environment variable to your development environment by editing
~/.bash_profile
or~/.zshenv
:
export COMPOSER_AUTH="{\"github-oauth\":{\"github.com\":\"{GITHUB_TOKEN}\"},\"gitlab-oauth\":{\"gitlab.com\":\"{GITLAB_TOKEN}\"},\"bitbucket-oauth\":{\"bitbucket.org\": {\"consumer-key\": \"{BITBUCKET_KEY}\", \"consumer-secret\": \"{BITBUCKET_SECRET}\"}}}"
- Re-build the application:
docker/sdk up --build
You’ve configured authentication to your private repositories.
Thank you!
For submitting the form