Configure access to private repositories
Edit on GitHubThis document describes how to configure an environment to allow the Docker SDK access 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.
Configure an environment to access private repositories
- 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:
- Configure SSH agent authentication for Composer. We recommend this option for development purposes.
- Configure the Composer authentication environment variable. We recommend this option for setting up CI/CD pipelines.
Configure SSH agent authentication for Composer
- Remove the
GITHUB_TOKEN
andCOMPOSER_AUTH
environment variables:
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
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