Search code examples
dockervolume

Docker: add a volume


I am running three docker instances of multichain nodes for testing purposes. Now in the Readme it says that I have to add a volume:

Add a volume

:/root/.multichain

Link to GitHub

So my question is very simple: How do I add this volume? is :/root/.multichain a path of the host system or is it some relative path inside the docker container?

Thanks a lot


Solution

  • It leaves how do you map your volume up to you (namely giving you 2 persistent options). This Readme only defines what location in container should be persisted.

    Method 1 (named volume)

    version: '2'
    services:
        masternode:
            build: ./master
            volumes:
               - namedvolume:/root/.multichain
            # further definitions
    
        slavenode:
            build: ./node
            volumes:
               - namedvolume:/root/.multichain
            # further definitions
    
        explorernode:
            build: ./explorer
            volumes:
               - namedvolume:/root/.multichain
            # further definitions
    
        # further services definitions
    

    Method 2 (direct mapping into host):

    version: '2'
    services:
        masternode:
            build: ./master
            volumes:
               - /some/path/in/host:/root/.multichain
            # further definitions
    
        slavenode:
            build: ./node
            volumes:
               - /some/path/in/host:/root/.multichain
            # further definitions
    
        explorernode:
            build: ./explorer
            volumes:
               - /some/path/in/host:/root/.multichain
            # further definitions
    
        # further services definitions
    

    Note that this volume should be shared across all the services so that all the services (nodes in this case) will have the same files and will be able to maintain the same state.

    Official docs ref and further reading