AnsweredAssumed Answered

Dockerized CA API Gateway can't connect to MySQL container

Question asked by jinola on May 17, 2017
Latest reply on May 20, 2017 by Stephen_Hughes

I'm trying to setup a pair of Docker containers to host the CA API Gateway and its supporting MySQL database. Here's the relevant portion of my docker-compose.yml:

  gateway-db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_USER=test
      - MYSQL_PASSWORD=password
      - MYSQL_DATABASE=ssg
    networks:
      gateway_net:
        ipv4_address: 10.1.2.3

  gateway:
    image: caapim/gateway
    environment:
      SSG_CLUSTER_COMMAND: join
      SSG_CLUSTER_HOST: localhost
      SSG_CLUSTER_PASSWORD: 7layer
      SSG_DATABASE_TYPE: mysql
      SSG_DATABASE_HOST: gateway-db
      SSG_DATABASE_PORT: 3306
      SSG_DATABASE_NAME: ssg
      SSG_DATABASE_USER: test
      SSG_DATABASE_PASSWORD: password
      SSG_DATABASE_ADMIN_USER: root
      SSG_DATABASE_ADMIN_PASS: password
      SSG_ADMIN_USER: admin
      SSG_ADMIN_PASS: password
    networks:
      #suite_net:
      #  ipv4_address: 10.1.1.4
      gateway_net:
        ipv4_address: 10.1.2.2
      #client_net:
      #  ipv4_address: 10.1.0.3

 

Unfortunately, when I try to `docker-compose up`, the Gateway is unable to connect to the MySQL database:

[vagrant@vagrantbox ~]$ docker-compose logs gateway
Attaching to vagrant_gateway_1
gateway_1     | apim-provisioning: INFO: checking if a Consul server has been set in the SSG_CONSUL_IP environment variable
gateway_1     | apim-provisioning: INFO: no Consul server set via the SSG_CONSUL_IP environment variable
gateway_1     | apim-provisioning: INFO: checking for an etcd server
gateway_1     | apim-provisioning: INFO: no etcd server available (neither ETCDCTL_ENDPOINT nor ETCDCTL_DISCOVERY_SRV were set in the environment
gateway_1     | apim-provisioning: INFO: validating the collected config
gateway_1     | apim-provisioning: INFO: done validating the collected config
gateway_1     | apim-provisioning: INFO: starting the process controller
gateway_1     | Starting Gateway Services: [  OK  ]
gateway_1     | apim-provisioning: INFO: waiting for the process controller to start up
gateway_1     | apim-provisioning: INFO: process controller is not running yet.
gateway_1     | apim-provisioning: INFO: process controller is not running yet.
gateway_1     | apim-provisioning: INFO: waiting for MySQL to become ready
gateway_1     | apim-provisioning: INFO: running gateway's headless autoconfig
gateway_1     | Exception configuring gateway: Error saving configuration 'Error during node configuration 'Database connection error 'Access denied for user 'test'@'10.1.2.2' (using password: YES)'.''
gateway_1     | apim-provisioning: ERROR: gateway headless autoconfig failed
gateway_1     | apim-provisioning: INFO: checking if a Consul server has been set in the SSG_CONSUL_IP environment variable
gateway_1     | apim-provisioning: INFO: no Consul server set via the SSG_CONSUL_IP environment variable
gateway_1     | apim-provisioning: INFO: checking for an etcd server
gateway_1     | apim-provisioning: INFO: no etcd server available (neither ETCDCTL_ENDPOINT nor ETCDCTL_DISCOVERY_SRV were set in the environment
gateway_1     | apim-provisioning: INFO: validating the collected config
gateway_1     | apim-provisioning: INFO: done validating the collected config
gateway_1     | apim-provisioning: INFO: starting the process controller
gateway_1     | Starting Gateway Services: [  OK  ]
gateway_1     | apim-provisioning: INFO: waiting for the process controller to start up
gateway_1     | apim-provisioning: INFO: process controller is not running yet.
gateway_1     | apim-provisioning: INFO: process controller is not running yet.
gateway_1     | apim-provisioning: INFO: waiting for MySQL to become ready
gateway_1     | apim-provisioning: INFO: running gateway's headless autoconfig
gateway_1     | Exception configuring gateway: Error saving configuration 'Error during node configuration 'Database connection error 'Access denied for user 'test'@'10.1.2.2' (using password: YES)'.''
gateway_1     | apim-provisioning: ERROR: gateway headless autoconfig failed

 

Based on the last few lines, it seems that the API Gateway appears to be attempting to connect to the MySQL database '10.1.2.2' hosted on IP address 10.1.2.2, instead of connecting to the database 'ssg'. Is there another way to force the Gateway to connect to the 'ssg' database (overriding the $SSG_DATABASE_NAME/$SSG_DATABASE_HOST collision that appears to be the problem)?

Outcomes