oras
can push/pull any files to/from any registry with OCI image support.
Registries with known support:
- Distribution (open source, version 2.7+)
- Azure Container Registry
For more background on this topic, please see this post.
oras
is a CLI that allows you to push and pull files from
any registry with OCI image support.
oras push localhost:5000/hello:latest hi.txt
The default media type for all files is application/vnd.oci.image.layer.v1.tar
.
The push a custom media type, use the format filename[:type]
:
oras push localhost:5000/hello:latest hi.txt:application/vnd.me.hi
To push multiple files with different media types:
oras push localhost:5000/hello:latest hi.txt:application/vnd.me.hi bye.txt:application/vnd.me.bye
oras pull localhost:5000/hello:latest
By default, only blobs with media type application/vnd.oci.image.layer.v1.tar
will be downloaded.
To specify which media types to download, use the --media-type
/-t
flag:
oras pull localhost:5000/hello:latest -t application/vnd.me.hi
Or to allow all media types, use the --allow-all
/-a
flag:
oras pull localhost:5000/hello:latest -a
oras
uses the local docker credential by default. Please run docker login
in advance for any private registries.
oras
also accepts explicit credentials via options. For example,
oras pull -u username -p password myregistry.io/myimage:latest
Public image is available on Docker Hub at ocistorage/oras
docker run --rm -it -v $(pwd):/workplace ocistorage/oras:v0.3.0 \
pull myregistry.io/hello:latest
docker run --rm -it -v ${pwd}:/workplace ocistorage/oras:v0.3.0 \
pull myregistry.io/hello:latest
docker run --rm -it -v %cd%:/workplace ocistorage/oras:v0.3.0 \
pull myregistry.io/hello:latest
Install from latest release (v0.3.0):
# on Linux
curl -LO https://github.com/shizhMSFT/oras/releases/download/v0.3.0/oras_0.3.0_linux_amd64.tar.gz
# on macOS
curl -LO https://github.com/shizhMSFT/oras/releases/download/v0.3.0/oras_0.3.0_darwin_amd64.tar.gz
# on Windows
curl -LO https://github.com/shizhMSFT/oras/releases/download/v0.3.0/oras_0.3.0_windows_amd64.tar.gz
mkdir -p oras/
tar -zxf oras_0.3.0_*.tar.gz -C oras/
mv oras/bin/oras /usr/local/bin/
rm -rf oras_0.3.0_*.tar.gz oras/
Then, to run:
oras help
The checksums for the .tar.gz
files above can be found here.
The package github.com/shizhMSFT/oras/pkg/oras
can quickly be imported in other Go-based tools that
wish to benefit from the ability to store arbitrary content in container registries.
Example:
package main
import (
"context"
"fmt"
"github.com/containerd/containerd/remotes/docker"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/shizhMSFT/oras/pkg/content"
"github.com/shizhMSFT/oras/pkg/oras"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
ref := "localhost:5000/oras:test"
fileName := "hello.txt"
fileContent := []byte("Hello World!\n")
customMediaType := "my.custom.media.type"
ctx := context.Background()
resolver := docker.NewResolver(docker.ResolverOptions{})
// Push file(s) w custom mediatype to registry
memoryStore := content.NewMemoryStore()
desc := memoryStore.Add(fileName, customMediaType, fileContent)
pushContents := []ocispec.Descriptor{desc}
fmt.Printf("Pushing %s to %s... ", fileName, ref)
err := oras.Push(ctx, resolver, ref, memoryStore, pushContents)
check(err)
fmt.Println("success!")
// Pull file(s) from registry and save to disk
fmt.Printf("Pulling from %s and saving to %s... ", ref, fileName)
fileStore := content.NewFileStore("")
allowedMediaTypes := []string{customMediaType}
_, err = oras.Pull(ctx, resolver, ref, fileStore, allowedMediaTypes...)
check(err)
fmt.Println("success!")
fmt.Printf("Try running 'cat %s'\n", fileName)
}