1

I'm trying to start Vault docker container with mysql storage using this command:

docker run  --cap-add=IPC_LOCK  -e 'VAULT_LOCAL_CONFIG={"storage": {"mysql": {"username":"root", "password":"hello", "database":"vault", "address":"127.0.0.1:3306"}}, "listener": {"tcp":{"address":"127.0.0.1:8200", "tls_disable":"1"}}, "default_lease_ttl": "168h", "max_lease_ttl": "720h"}' -e VAULT_SKIP_VERIFY=true vault server

This is the error I'm getting:

Error initializing storage of type mysql: failed to check mysql schema exist: dial tcp 127.0.0.1:3306: connect: connection refused

I can connect to mysql using the username and password I am supplying to the previous command.

I also made sure that the mysql is running on the 3306 port

[root@jwahba]# netstat -tlpn | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      39552/mysqld   

I checked out the vault official document (here) but it's not obvious what is wrong in my configuration. Any suggestions please ?

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Joseph Wahba
  • 660
  • 3
  • 9
  • 25
  • Have you addded certificates to the MySql DB? If so, you should tell Vault to use them to connect – gic186 Jun 07 '18 at 07:59

1 Answers1

1

You are trying to connect to a db on localhost from a Docker container, but they are on different network stacks. Use --net="host" in your docker run command; 127.0.0.1 in your docker container will now point to your docker host.

Source: From inside of a Docker container, how do I connect to the localhost of the machine?

gic186
  • 786
  • 6
  • 18