...
- A running Docker environment with an internet connection.
- A running Swarm cluster with S3 exposed.
There are a few different methods of Note that you can choose between two methods for setting up the container so i'll list them below.:
- Docker run with an add-in config file
- Docker run with environment variables
...
Pull the registry image
First, you need to pull the docker image for the current version of the registry .At (which, at the time of writing that , is version 2.7):First we run
Code Block |
---|
docker pull registry:2.7 |
...
|
...
|
...
2.7 |
...
: Pulling from library/registry |
...
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146 |
...
Status: Image is up to date for registry:2.7 |
These commands will pull This pulls down the docker container from the public registry to your local docker host.
The host will then be able run the container via a docker run
command like so:
Code Block |
---|
docker run -d -p 5000:5000 --restart always --name registry:2.7 |
This command would run a docker registry with local storage bound to port 5000 on the host.
To get the S3 element, we can start with a config file
Option 1: Configure with YAML file
You can set up S3 using a YAML config file. The Docker configuration documentation starts with this example:
https://raw.githubusercontent.com/docker/distribution/master/cmd/registry/config-example.yml
Code Block |
---|
version: 0.1
log:
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
auth:
htpasswd:
realm: basic-realm
path: /etc/registry
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3 |
...
The elements we need to change /add are in the storage
sectionwe'll replace.
Replace storage: | with S3: | |
---|---|---|
|
...
|
...
|
...
|
...
|
...
|
in my case my Example of a full config.yml looks like:
Code Block |
---|
version: 0.1 |
...
log: |
...
fields: |
...
service: registry |
...
storage: |
...
cache: |
...
blobdescriptor: inmemory |
...
s3: |
...
accesskey: 480ee4b88c3380b70d957a3fb2d69054 |
...
secretkey: test |
...
region: us-west-1 |
...
regionendpoint: http://dockertest.caringo.com |
...
bucket: registry1 |
...
secure: false |
...
v4auth: true |
...
chunksize: 5242880 |
...
multipartcopychunksize: 33554432 |
...
multipartcopymaxconcurrency: 100 |
...
multipartcopythresholdsize: 33554432 |
...
http: |
...
addr: :5000 |
...
headers: |
...
X-Content-Type-Options: [nosniff] |
To run the above yml
docker run -d -p Save the config file and do a run
to apply it:
Code Block |
---|
docker run -d -p 5000:5000 --restart=always --name registryS3t2 -v `pwd`/config.yml:/etc/docker/registry/config.yml registry:2.7 |
In this case it would This causes docker to start a container named registryS3t2 and , pull the config yml would be pulled file from /config.yml
, and overwrite the one in the container.
All of the above could also be done with environment variables as follows.
...
Option 2: Configure with environment variables
You could do the same configuration using environment variables. Run docker and supply all of these values:
Code Block |
---|
docker run -d -p 5000:5000 --name registry --restart=always \ -e REGISTRY_STORAGE=s3 \ -e REGISTRY_STORAGE_S3_REGION=us-east-1 \ -e REGISTRY_STORAGE_S3_BUCKET=your.bucket.example.com |
...
\ -e REGISTRY_STORAGE_S3_ROOTDIRECTORY=docker-registry-exp1 \ -e REGISTRY_STORAGE_S3_V4AUTH=false \ -e REGISTRY_STORAGE_S3_ACCESSKEY=480ee4b88c3380b70d957a3fb2d69054 \ -e REGISTRY_STORAGE_S3_SECRETKEY=secret registry:2.7 |
...
Push containers to registry
Once your registry is up and running, you can download containers and push them to your local registry.
root@Lab-production-docker:~/dockerregistry# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
Digest: sha256:b88f8848e9a1a4e4558ba7cfc4acc5879e1d0e7ac06401409062ad2627e6fb58
...
Code Block |
---|
docker pull ubuntu Using default tag: latest latest: Pulling from library/ubuntu Digest: sha256:b88f8848e9a1a4e4558ba7cfc4acc5879e1d0e7ac06401409062ad2627e6fb58 Status: Downloaded newer image for ubuntu:latest |
Next we , tag
the pulled image we've pulled with info for our the local registryroot@Lab-production-docker:~/dockerregistry# docker image tag ubuntu :
Code Block |
---|
docker image tag ubuntu localhost:5000/myfirstimage |
Then when with push
the image it will push it to our the S3-enabled Swarm cluster.root@Lab-production-docker:~/dockerregistry# docker push :
Code Block |
---|
docker push localhost:5000/myfirstimage |
...
The push refers to repository [localhost:5000/myfirstimage]
e80c789bc6ac: Mounted from my-ubuntu |
...
6c3332381368: Mounted from my-ubuntu |
...
ef1a1ec5bba9: Mounted from my-ubuntu |
...
a1aa3da2a80a: Mounted from my-ubuntu |
...
latest: digest: sha256:1bbdea4846231d91cce6c7ff3907d26fca444fd6b7e3c282b90c7fe4251f9f86 size: 1152 |
root@Lab-production-docker:~/dockerregistry# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d3b5f0c552e4 The push refers to the repository [localhost:5000/myfirstimage].
Use docker ps
to list your containers:
Code Block |
---|
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d3b5f0c552e4 registry:2.7 "/entrypoint.sh /etc…" 7 days ago Up 7 days 0.0.0.0:5000->5000/tcp |
...
registryS3t2 |
With that done, your local developers will be able to push containers from their local machines to this registry using the forward-facing IP and port.
Info | ||
---|---|---|
| ||
The config file example shows how to interact with the storage and is sufficient only for a small lab environment. To put the registry into production, more configuration is required. Follow the Docker registry configuration guidance: |
...
Page Properties | ||
---|---|---|
| ||
|