You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-31Lines changed: 39 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,30 @@
1
1
# Introduction
2
-
This project teaches Docker some IPFS. IPFS is a global, versioned, peer-to-peer filesystem. It combines good ideas from Git, BitTorrent, Kademlia, SFS, and the Web. It is like a single bittorrent swarm, exchanging git objects.
2
+
This project teaches Docker some IPFS. IPFS is a global, versioned, peer-to-peer filesystem. IPFS combines good ideas from Git, BitTorrent, Kademlia, SFS, and the Web. It is like a single bittorrent swarm, exchanging git objects.
3
3
[https://github.com/ipfs/go-ipfs]
4
4
5
5
image2ipfs works only with images prduced docker >= 1.10. On the bright side, all post-1.6 dockers can pull from an ipfs-registry.
6
6
7
7
# How does it work?
8
+
8
9
image2ipfs takes an image archive produced using `docker save`.
9
10
The archive is extracted to a temp location then processed a bit. Finally, it is added to IPFS using `ipfs add -r`
10
11
(you need to have the ipfs binary in your `PATH`). For a simple busybox image
_v1 Manifests are not supported starting with version 0.0.6_
23
24
But how do you get from something like QmQSF1oN4TXeU2kRvmjerEs62ZYfKPyRCqPvW1XTTc4fLS to a working `docker pull busybox`?
24
25
25
26
The answer is simple: using url rewriting. In the `registry/` subdirectory of the project
26
-
there is a trivial Flask application that speaks the Registry v2 protocol but instead of serving the blobs and manifests it redirects
27
+
there is a trivial Go application that speaks the Registry v2 protocol but instead of serving the blobs and manifests it redirects
27
28
to an IPFS gateway of your choice.
28
29
29
30
When pulling REPO:latest (with REPO=busybox in this example), Docker daemon will issue these requests:
@@ -34,9 +35,14 @@ GET /v2/REPO/blobs/sha256:47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe6
34
35
GET /v2/REPO/blobs/sha256:193bda8d9ac77416619eb556391a9c5447adb2abf12aab515d1b0c754637eb80
35
36
GET /v2/REPO/blobs/sha256:a1b1b81d3d1afdb8fe119b002318c12c20934713b9754a40f702adb18a2540b9
36
37
```
37
-
So somehow you need encode the IPFS hash in `REPO`, then use it on the server to redirect to https://ipfs.io/ipfs/{HASH}/{NAME}/manifest/latest-v1.
38
-
See Section "Demo" bellow for how this plays.
39
38
39
+
All the Go app does is produce IPFS links to a an IPFS gateway and redirect docker there:
40
+
```
41
+
GET /ipfs/HASH/manifest/latest
42
+
GET /ipfs/HASH/blobs/sha256:47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb
43
+
GET /ipfs/HASH/blobs/sha256:193bda8d9ac77416619eb556391a9c5447adb2abf12aab515d1b0c754637eb80
44
+
GET /ipfs/HASH/blobs/sha256:a1b1b81d3d1afdb8fe119b002318c12c20934713b9754a40f702adb18a2540b9
45
+
```
40
46
41
47
42
48
# Installation
@@ -48,33 +54,35 @@ $ cd image2ipfs
48
54
$ make install
49
55
50
56
$ image2ipfs -v
51
-
0.0.4
57
+
0.0.6
52
58
```
53
59
54
-
If someone else will be running an ipfs-registry then you can install image2ipfs using pip
60
+
You can also install using pip
55
61
```bash
56
62
$ pip install image2ipfs
57
63
58
64
$ image2ipfs -v
59
-
65
+
0.0.6
60
66
```
61
67
62
68
# Running the registry
63
-
You can pull from dockerhub. The second command requires less configuration but is less flexible.
64
-
```
65
-
docker run -td --name ipfs-registry -e IPFS_GATEWAY=http://{public-ip}:8080 -p 5000:5000 jvassev/ipfs-registry
69
+
You can pull the official image from dockerhub. This example assumes the gateway is running on localhost. Consider using another gateway address as image2ipfs will serve redirects to it.
66
70
71
+
```
67
72
docker run -td --name ipfs-registry -e IPFS_GATEWAY=http://localhost:8080 --net host jvassev/ipfs-registry
68
73
```
69
74
70
75
Or build from source:
71
76
```bash
72
-
cd image2ipfs/registry
73
-
make build run IPFS_GATEWAY=http://localhost:8080
77
+
# build image locally
78
+
make build-image
79
+
80
+
# or install to $GOPATH/bin
81
+
make install
74
82
```
75
-
This will start a flask application pretending to be a docker registry on http://localhost:5000
76
83
77
84
# Configure Docker
85
+
78
86
As usual add `--insecure-registry localhost:5000` to your docker daemon args
79
87
80
88
# Demo
@@ -98,7 +106,7 @@ Server:
98
106
OS/Arch: linux/amd64
99
107
100
108
$ image2ipfs -v
101
-
0.0.4
109
+
0.0.6
102
110
103
111
$ docker pull centos:7
104
112
7: Pulling from library/centos
@@ -143,16 +151,15 @@ Status: Image is up to date for localhost:5000/ciqn5zu57ciucp3gw2hwxymuwz3tgjlvf
143
151
144
152
$ docker history localhost:5000/ciqn5zu57ciucp3gw2hwxymuwz3tgjlvfdfwg3xhwx456y4xxydkhmq/centos
145
153
IMAGE CREATED CREATED BY SIZE COMMENT
146
-
778a53015523 4 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
147
-
<missing> 4 weeks ago /bin/sh -c #(nop) LABEL name=CentOS Base Imag 0 B
<missing> 7 months ago /bin/sh -c #(nop) MAINTAINER The CentOS Proje 0 B
150
158
```
151
159
152
160
Depending on how you have started the ipfs-registry the docker daemon will be redirected to an IPFS gateway of your choice. By default the registry
153
161
will redirect to the ipfs daemon running locally (http://localhost:8080).
154
162
155
-
156
163
But what is this "Dockerized hash ciqn5zu57ciucp3gw2hwxymuwz3tgjlvfdfwg3xhwx456y4xxydkhmq" in the output?
157
164
Docker requires image names to be all lowercase which doesn't play nicely with base58-encoded binary. A dockerized IPFS hash
158
165
is just a base-32 of the same binary value. This is the reason why the ipfs-registry is not a simple nginx+rewrite rules: you need
@@ -161,25 +168,23 @@ to do base-32 to base-58 conversions. If you see a string starting with `ciq` th
161
168
162
169
In automated scenarios you'd probably want to run image2ipfs like this:
163
170
```bash
164
-
$ docker built -t $TAG.
171
+
172
+
# build whatever images
173
+
$ docker built -t $TAG ...
165
174
$ docker save $TAG| image2ipfs -q -r my-gateway.local:9090 | tee pull-url.txt
166
175
my-gateway.local:9090/ciq..../centos
167
176
```
168
177
169
-
`-r my-gateway.local` instructs image2ipfs what pull url to produce.
170
-
Then you can distribute the pull-url.txt to downstream jobs that need to pull the image.
178
+
`-r my-gateway.local` instructs image2ipfs what pull url to produce. In a CI/CD you can distribute this generated url to downstream jobs that need to pull it.
171
179
172
180
# What's next
173
-
Not sure. It would be great if an IPFS gateway could speak the Registry v2 protocol at /v2/* so you don't need to run a registry.
174
181
175
-
When an image exported and processed both v1 and v2 versions of the manifests are produced. v1 manifest are not thoroughly tested though.
176
-
The flask app reads the `Accepts` header and redirects to either latest-v1 or latest-v2. But the redirection is not to
177
-
the IPFS gateway but to the same service which acts as a proxy just so that it can set the 'Content-type' header.
178
-
Proxying small json documents is OK but if IPFS can store the mime-type of a file then even the manifests can directly be served by a gateway
182
+
Not sure. It would be great if an IPFS gateway could speak the Registry v2 protocol at /v2/* so you don't need to run a registry.
179
183
180
184
The Dockerized hash can be shortened a bit if base-36 is used instead of base-32/hex.
0 commit comments