The reason for persisting the data is that every time i run the ganache-cli container , the deployed smart contracts address changes each time i restart it .SO i am looking for a work around to either persist the data so that contract address wont change on frequent restart or else automatically deploy the contract and get the contract address out of it. For time being i have used the below statement to run ganache :

sudo docker run -d --name ganache --network=test1 --ip= -p 8545:8545 trufflesuite/ganache-cli:latest -i 2100 --db=path/to/ganache/data

however the data is not saved in ganache directory.let me know if you need any more clues.Thanks in advance!

2 Answers 2


There are multiple solutions for you.

  1. Use docker's -v option to mount the volume for storing the ganache-cli db outside of the container, so it can survive the restart.

  2. Use ganache-cli --mnemonic option to use the same accounts each time. This way, if you deploy your contracts in the same order with the same account, you'll have the same contract address every time. The contract adress depends on the address of the transaction sender and the nonce of this address.


One approach is to create a docker image that starts ganache-cli and runs maven to build, deploy and test the contracts. In the case the memonic phase has been used all the account will be the same with every start. Alternatively you may use the -d option to get always the same accounts.

-d or --deterministic: Generate deterministic addresses based on a pre-defined mnemonic.


    # Start with a base image containing Maven
    FROM maven:3-jdk-8

    # Copy sources
    COPY . /app

    # Install node.js
    RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - && apt-get install -y -qq nodejs

    # Install ganache-cli globally
    RUN npm install --quiet -g ganache-cli

    # Install other dependiencies
    RUN npm install --quiet

    # Create start script
    RUN echo '#!/bin/bash\n mvn -D"deploy-script=ganache" install -DskipTests & \n ganache-cli -h --mnemonic "concert ladder decline crumble mention because pepper address scan volco pulse pig" --gasLimit 8000000 \n' > /app/startscript.sh && chmod +x /app/startscript.sh

    # Set the /app directory as working directory
    WORKDIR /app

    # Set the default command for the image
    CMD ["./startscript.sh"]

Here maven will be started and then ganache-cli. Because ganache-cli is very fast it will be available for the deployment and tests execution in maven.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.