|
1 | 1 | # OCI Registry As Storage |
2 | | -`oras` can push/pull any files from/to any registry with OCI support. |
| 2 | +`oras` can push/pull any files from/to any registry with OCI image support. |
3 | 3 |
|
4 | | -If you are using [docker/distribution](https://github.com/docker/distribution), please make sure the version is `2.7.0` or above. |
| 4 | +Registries with known support: |
5 | 5 |
|
6 | | -## Push files to remote registry |
| 6 | +- [Distribution](https://github.com/docker/distribution) (open source, version 2.7+) |
| 7 | +- [Azure Container Registry](https://azure.microsoft.com/en-us/services/container-registry/) |
| 8 | + |
| 9 | +For more backgound on this topic, please see |
| 10 | +[this post](https://www.opencontainers.org/blog/2018/10/11/oci-image-support-comes-to-open-source-docker-registry). |
| 11 | + |
| 12 | +## CLI |
| 13 | + |
| 14 | +`oras` is a CLI that allows you to push and pull files from |
| 15 | +any registry with OCI image support. |
| 16 | + |
| 17 | +### Push files to remote registry |
7 | 18 | ``` |
8 | 19 | oras push localhost:5000/hello:latest hello.txt |
9 | 20 | ``` |
10 | 21 |
|
11 | | -## Pull files from remote registry |
| 22 | +### Pull files from remote registry |
12 | 23 | ``` |
13 | 24 | oras pull localhost:5000/hello:latest |
14 | 25 | ``` |
15 | 26 |
|
16 | | -## Login Credentials |
| 27 | +### Login Credentials |
17 | 28 | `oras` uses the local docker credential by default. Therefore, please run `docker login` in advance for any private registries. |
18 | 29 |
|
19 | 30 | `oras` also accepts explicit credentials via options. For example, |
20 | 31 | ``` |
21 | 32 | oras pull -u username -p password myregistry.io/myimage:latest |
22 | 33 | ``` |
23 | 34 |
|
24 | | -## Running in Docker |
25 | | -### Build the image |
| 35 | +### Running in Docker |
| 36 | +#### Build the image |
26 | 37 | ``` |
27 | 38 | docker build -t oras . |
28 | 39 | ``` |
29 | 40 |
|
30 | | -### Run on Linux |
| 41 | +#### Run on Linux |
31 | 42 | ``` |
32 | 43 | docker run --rm -it -v $(pwd):/workplace oras pull localhost:5000/hello:latest |
33 | 44 | ``` |
34 | 45 |
|
35 | | -### Run on Windows PowerShell |
| 46 | +#### Run on Windows PowerShell |
36 | 47 | ``` |
37 | 48 | docker run --rm -it -v ${pwd}:/workplace oras pull localhost:5000/hello:latest |
38 | 49 | ``` |
39 | 50 |
|
40 | | -### Run on Windows Commands |
| 51 | +#### Run on Windows Commands |
41 | 52 | ``` |
42 | 53 | docker run --rm -it -v %cd%:/workplace oras pull localhost:5000/hello:latest |
43 | 54 | ``` |
| 55 | + |
| 56 | +## Go Module |
| 57 | + |
| 58 | +The package `github.com/shizhMSFT/oras/pkg/oras` can quickly be imported in other Go-based tools that |
| 59 | +wish to benefit from the ability to store arbitrary content in container registries. |
| 60 | + |
| 61 | +Example: |
| 62 | + |
| 63 | +[Source](examples/simple_push_pull.go) |
| 64 | + |
| 65 | +```go |
| 66 | +package main |
| 67 | + |
| 68 | +import ( |
| 69 | + "context" |
| 70 | + "fmt" |
| 71 | + "github.com/containerd/containerd/remotes/docker" |
| 72 | + "github.com/shizhMSFT/oras/pkg/oras" |
| 73 | + "io/ioutil" |
| 74 | +) |
| 75 | + |
| 76 | +func check(e error) { |
| 77 | + if e != nil { |
| 78 | + panic(e) |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +func main() { |
| 83 | + ref := "localhost:5000/oras:test" |
| 84 | + fileName := "hello.txt" |
| 85 | + fileContent := []byte("Hello World!\n") |
| 86 | + |
| 87 | + ctx := context.Background() |
| 88 | + resolver := docker.NewResolver(docker.ResolverOptions{}) |
| 89 | + |
| 90 | + // Push file(s) to registry |
| 91 | + pushContents := make(map[string][]byte) |
| 92 | + pushContents[fileName] = fileContent |
| 93 | + fmt.Printf("Pushing %s to %s... ", fileName, ref) |
| 94 | + err := oras.Push(ctx, resolver, ref, pushContents) |
| 95 | + check(err) |
| 96 | + fmt.Println("success!") |
| 97 | + |
| 98 | + // Pull file(s) from registry and save to disk |
| 99 | + fmt.Printf("Pulling from %s and saving to %s... ", ref, fileName) |
| 100 | + pullContents, err := oras.Pull(ctx, resolver, ref) |
| 101 | + check(err) |
| 102 | + err = ioutil.WriteFile(fileName, pullContents[fileName], 0644) |
| 103 | + check(err) |
| 104 | + fmt.Println("success!") |
| 105 | + fmt.Printf("Try running 'cat %s'\n", fileName) |
| 106 | +} |
| 107 | +``` |
0 commit comments