OpenZeppelin CLI and docker: Could not connect to the development Ethereum network on http://localhost:8545

Hi all;
I got new update regarding docker deploy;
The issues is docker service can not deploy contract to chosen network with error:

Could not connect to the development Ethereum network on http://localhost:8545. Please check your networks.js configuration file. Error: Invalid JSON RPC response: "".

here is the code to reproduce

1 Like

Hi @rad-p,

OpenZeppelin CLI network configuration by default is looking for a development network at http://localhost:8545

For details on running ganache-cli on Docker see the ganache-cli documentation:

I assume that you either need to change the OpenZeppelin CLI network configuration or the host name for ganache.

The default OpenZeppelin CLI network.js is as follows:

network.js

module.exports = {
  networks: {
    development: {
      protocol: 'http',
      host: 'localhost',
      port: 8545,
      gas: 5000000,
      gasPrice: 5e9,
      networkId: '*',
    },
  },
};

I haven’t played with Docker so don’t know any more about the setup.

The npx openzeppelin init test --no-interactive command inside dockerfile, creates default networks.js file

module.exports = {
  networks: {
    development: {
      protocol: 'http',
      host: 'localhost',
      port: 8545,
      gas: 5000000,
      gasPrice: 5e9,
      networkId: '*',
    },
  },
};

docker-compose creates internal network between services – but still the error occurs ;(

btw. added log into docker file to print networks file;

On other hand I tried the approach to copy already initialized oz project from host to container, (copying .openzeppelin and networks.js) and still resulted with same error

1 Like

Hi @rad-p,

I run locally with no issues, so suspect that the issue is the connection from OpenZeppelin CLI in one container calling http://localhost:8545 to the container running ganache-cli.

Unfortunately my docker setup is problematic so not something I can easily reproduce.

Are you able to try locally?

Locally everything works fine;

I managed to fix the issue by setting network_mode to host in each service. I do not know whether it is a correct solution, but now it works.

fixed in dbe4bbc

1 Like

Hi @rad-p,

I’m glad that you were able to resolve. Sorry I couldn’t help with the network config on the docker side.

1 Like