From dbc4a0e79e550c2ce620bce835b359f6ec9e4554 Mon Sep 17 00:00:00 2001 From: Andrey Arapov Date: Sat, 29 Dec 2018 13:52:07 +0100 Subject: [PATCH] firt commit --- .dockerignore | 1 + Dockerfile | 14 ++++++++++ README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++ data/.gitignore | 2 ++ docker-compose.yml | 12 +++++++++ launch | 10 ++++++++ sha512sum.txt | 1 + 7 files changed, 104 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 data/.gitignore create mode 100644 docker-compose.yml create mode 100755 launch create mode 100644 sha512sum.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8fce603 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +data/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f49c187 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM ubuntu:bionic +# https://dist.ipfs.io/go-ipfs/v0.4.18/go-ipfs_v0.4.18_linux-amd64.tar.gz +COPY sha512sum.txt . +RUN apt-get -qq update && \ + DEBIAN_FRONTEND=noninteractive apt-get -qqy install wget gosu +RUN wget -q -O go-ipfs.tar.gz https://files.nixaid.com/go-ipfs_v0.4.18_linux-amd64.tar.gz && \ + sha512sum -c sha512sum.txt && \ + tar xf go-ipfs.tar.gz -C /opt && \ + rm go-ipfs.tar.gz +RUN find /opt/ -type f -name "ipfs" -exec ln -sv '{}' /usr/local/bin/ \; + +COPY ./launch /launch +ENTRYPOINT [ "/bin/sh", "/launch" ] +LABEL maintainer="Andrey Arapov " diff --git a/README.md b/README.md new file mode 100644 index 0000000..495bab2 --- /dev/null +++ b/README.md @@ -0,0 +1,64 @@ +## IPFS in Docker + +### Usage + +Start the IPFS: + +``` +docker-compose up -d +``` + +This will initialize the node under ``data/.ipfs`` directory. + +Then prepare the following functions and add them to your ``~/.bash_aliases`` file: + +``` +function docker_helper_up() { + command cd ~/git/$1 + docker-compose up -d "$1" + command cd ~- +} + +function docker_helper_exec_u() { + command cd ~/git/$1 + docker-compose exec -w /home/user -u user "$1" "$@" + command cd ~- +} + +function ipfs-daemon() { + docker_helper_up ipfs +} + +function ipfs() { + docker_helper_exec_u "$FUNCNAME" "$@" +} +``` + +Now you can use ipfs command as normal: + +``` +$ ipfs id +$ ipfs swarm addrs --local +$ ipfs pin ls -q --type recursive +$ ipfs ls QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv +$ ipfs cat QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/quick-start + +$ mkdir data/public +$ cp ~/Downloads/dog-on-moon.gif data/public +$ ipfs add -rw public + +$ ipfs ls Qmdd7jNjEM4RXEnG8Y4ZikaqN6PUJkZ6bZuJZySEaFcuqY +QmagwXL3P4vPKiehXaPzYsHWc2F4hcPpnYEmm1AgQ4QLrU 2177241 dog-on-moon.gif + +$ ipfs cat Qmdd7jNjEM4RXEnG8Y4ZikaqN6PUJkZ6bZuJZySEaFcuqY/dog-on-moon.gif | sha256sum +03f9ccb5d2a0e88acb60188e627042ef143c7fe5426c883863e78e66dab908d7 - +$ sha256sum ~/Downloads/dog-on-moon.gif +03f9ccb5d2a0e88acb60188e627042ef143c7fe5426c883863e78e66dab908d7 /home/arno/Downloads/dog-on-moon.gif + +$ curl -s https://ipfs.io/ipfs/Qmdd7jNjEM4RXEnG8Y4ZikaqN6PUJkZ6bZuJZySEaFcuqY/dog-on-moon.gif | sha256sum +03f9ccb5d2a0e88acb60188e627042ef143c7fe5426c883863e78e66dab908d7 - +``` + +### Links + +- https://ipfs.github.io/public-gateway-checker/ diff --git a/data/.gitignore b/data/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/data/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4aefc24 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.7' + +services: + ipfs: + init: true + build: . + network_mode: bridge + volumes: + - ./data:/home/user + cap_add: + - IPC_LOCK # lock memory to prevent sensitive values from being swapped to disk. + shm_size: 128M diff --git a/launch b/launch new file mode 100755 index 0000000..af11523 --- /dev/null +++ b/launch @@ -0,0 +1,10 @@ +#!/bin/bash +set -x +# +# Make errors visible upon `docker logs -f steam` command +# +exec 2>&1 + +id user >/dev/null 2>&1 || useradd -s /usr/sbin/nologin -d /home/user -u ${UID:-1000} user +[ -d /home/user/.ipfs ] || gosu user ipfs init +gosu user ipfs daemon diff --git a/sha512sum.txt b/sha512sum.txt new file mode 100644 index 0000000..fccaa36 --- /dev/null +++ b/sha512sum.txt @@ -0,0 +1 @@ +ef5b44a0aaed604890c83322ca02228061204085b87b20dd173edfe6b6631fc7a54724d2e00202488c86886992a0d409f43e09f022cdf8b1138f8419cf7614b0 go-ipfs.tar.gz