Docker Community Forums

Share and learn in the Docker community.

Connection to mariadb container during build fails (111 "Connection refused")

testing
build
dockercloud

(Itsthejb) #1

Hi all,

I’m trying to write an automated test for my container, that verifies that the Dockerfile can connect to a “remote” mysql host during build. I’m simulating this by:

  • Starting a https://hub.docker.com/_/mariadb/ container at the start of my hooks/test
  • Using the container’s /docker-entrypoint-initdb.d feature to execute a very permissive GRANT to give remote access for the root user (for testing purposes)
  • Finding the build machine’s local ip using ip route get 1 | awk '{print $NF;exit}'
  • Using sed to insert the ip address into the test docker compose file using extra_hosts
  • Using links: - mariadb:database
  • Building using database as the mysql host name

This is admittedly a bit hacky, but works great locally (albeit on macOS, which requires some different commands for the IP address, although I’m handling this in the build script). However, when I build I get:

ERROR 2003 (HY000): Can't connect to MySQL server on 'database' (111 "Connection refused")

I believe this error means that the build is connecting to the MariaDB container, but the server is refusing it. Since this works locally, this suggests that something is different during the build on Cloud that is refusing this. Perhaps the use of the build machine’s IP address? Perhaps something security related?

Can anyone suggest why this happening, and perhaps some other way I could do this? It’s certainly a bit hacky, but I really need to test this feature somehow, since it’s rather important.

Hope someone can help! Thanks