Logo

Running IPFS on Docker

Spin up an IPFS node in less than 5 minutes

December 05, 2018IPFS, Docker

Don’t want to install go, and can’t even be bothered with the ipfs_version tool? If you’ve got Docker installed, let’s do this.

Setting Up the Docker Container

Step 1. Is Docker installed?

If not, install it.

Step 2. Create empty IPFS directories.

$ mkdir ~/.ipfs
$ mkdir ~/.ipfs/staging

Step 2. Run it!

The fun part about docker is that you can just… run stuff. So let’s run IPFS.

#!/bin/bash

export ipfs_staging=/home/[YOUR HOME DIR]/.ipfs/staging
export ipfs_data=/home/[YOUR HOME DIR]/.ipfs

docker run -d --init \
        --restart unless-stopped \
        --name ipfs_host \
        -v $ipfs_staging:/export \
        -v $ipfs_data:/data/ipfs \
        -w /export \
        -p 4001:4001 \
        -p 127.0.0.1:8080:8080 \
        -p 127.0.0.1:5001:5001 \
        ipfs/go-ipfs:v0.4.18

Let’s take these arguments one by one:

  • -d
    Run the container in a detached state.
  • --restart unless-stopped
    This does what it says, auto-restarting the container unless it’s stopped, but also has the feature of starting the container on system boot.
  • --name ipfs_host
    The name of the container is ipfs_host. You can change this to whatever you want.
  • -v $ipfs_staging:/export
    -v $ipfs_data:/data/ipfs
    Volume mounts. These map $ipfs_staging and $ipfs_data directories on your local machine to ~/.ipfs and /export on the docker container.
  • -w /export
    The working directory inside the container.
  • -p 4001:4001
    Globally expose port 4001, needed for swarming, to the outside world.
  • -p 127.0.0.1:8080:8080
    -p 127.0.0.1:5001:5001
    Expose ports 8080 (gateway) and 5001 (API) only locally.
  • ipfs/go-ipfs:latest
    The name of the container ifps/go-ipfs

What’s with this staging directory?

The staging directory is sort of a sandbox for you to run IPFS commands in, shared between the host machine and the container. See the section below for how to run commands like ipfs add and ipfs get.

Using the Docker Container

Add this function to your ~/.bash_aliases file, or similar:

function ipfs() {
  docker exec ipfs_host ipfs "$@"
}

Then, you can call regular commands like ipfs add or ipfs get.

Removing the Docker Container

$ docker stop ipfs_host # or whatever name you gave your container
$ docker rmi ipfs/go-ipfs
$ rm -rf ~/.ipfs

Let me know if you have any questions! My e-mail is below.

TallyLabLike reading about IPFS and want to see it in action? Check out my and @skybondsor's work on TallyLab
Follow the Discussion
Mark Robert Henderson

This is the website of Mark Robert Henderson. He lives in Cape Ann and works for Haja Networks on the decentralized, distributed, and federated front.

Mark's social media presence is slowly and deliberately withering away, so the best way to reach him is via e-mail.