title: Connection refused error when starting dockerized Spring Boot and MariaDb with docker-compose
body: <p>I am trying to dockerize a <code>Spring Boot</code> application alongside its <code>MariaDB</code> database using <code>docker-compose</code>, but I get the following error where I run containers using the command 'docker-compose up'</p>
  
  <pre><code>java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=localhost)(port=3306)(type=master) : Connection refused (Connection refused)
  </code></pre>
  
  <p>The service api uses the following <code>Dockerfile</code>:</p>
  
  <pre><code>FROM java:8
  EXPOSE 8080
  ADD target/cm-website-0.0.1-SNAPSHOT.jar cm-website.jar
  RUN bash -c 'touch /cm-website.jar'
  ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "-Dspring.profiles.active=development", "/cm-website.jar"]
  </code></pre>
  
  <p>My <code>docker-compose.yml</code> file is:</p>
  
  <pre><code>version: '3'
  
  services:
    db:
      container_name: backend-mariadb
      image: mariadb:latest
      environment:
        - MYSQL_ROOT_PASSWORD=pass
        - MYSQL_DATABASE=cmdb
        - MYSQL_USER=cmdb_user
        - MYSQL_PASSWORD=pass
      ports:
        - 3306:3306
    api:
      container_name: backend-api
      image: shaunyl/backend-api
      depends_on:
        - db
      build:
        context: .
        dockerfile: Dockerfile
      ports:
        - 8080:8080
  </code></pre>
  
  <p>My <code>application-development.yml</code> file is:</p>
  
  <pre><code>spring:
    profiles: development
    main:
      banner-mode: console
    jpa:
      show-sql: true
      generate-ddl: false
      database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    datasource:
      name: ds-dev-mariadb
      url: jdbc:mariadb://db:3306/cmdb&amp;useSSL=false
      username: cmdb_user
      password: pass
      driver-class-name: org.mariadb.jdbc.Driver
  </code></pre>
  
  <p>Do you know what the problem could be?
  Thank you</p>
  
  <p>EDIT 1: 
  Output of <code>docker logs backend-mariadb</code></p>
  
  <pre><code>2018-08-23 16:15:37 0 [Note] mysqld (mysqld 10.3.9-MariaDB-1:10.3.9+maria~bionic) starting as process 1 ...
  2018-08-23 16:15:37 0 [Note] InnoDB: Using Linux native AIO
  2018-08-23 16:15:37 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
  2018-08-23 16:15:37 0 [Note] InnoDB: Uses event mutexes
  2018-08-23 16:15:37 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
  2018-08-23 16:15:37 0 [Note] InnoDB: Number of pools: 1
  2018-08-23 16:15:37 0 [Note] InnoDB: Using SSE2 crc32 instructions
  2018-08-23 16:15:37 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
  2018-08-23 16:15:37 0 [Note] InnoDB: Completed initialization of buffer pool
  2018-08-23 16:15:37 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
  2018-08-23 16:15:37 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
  2018-08-23 16:15:37 0 [Note] InnoDB: Creating shared tablespace for temporary tables
  2018-08-23 16:15:37 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
  2018-08-23 16:15:37 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
  2018-08-23 16:15:37 0 [Note] InnoDB: 10.3.9 started; log sequence number 1630824; transaction id 21
  2018-08-23 16:15:37 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
  2018-08-23 16:15:37 0 [Note] Plugin 'FEEDBACK' is disabled.
  2018-08-23 16:15:37 0 [Note] Server socket created on IP: '::'.
  2018-08-23 16:15:37 0 [Warning] 'proxies_priv' entry '@% root@1b6a13ea879f' ignored in --skip-name-resolve mode.
  2018-08-23 16:15:37 0 [Note] InnoDB: Buffer pool(s) load completed at 180823 16:15:37
  2018-08-23 16:15:37 0 [Note] Reading of all Master_info entries succeded
  2018-08-23 16:15:37 0 [Note] Added new Master_info '' to hash table
  2018-08-23 16:15:37 0 [Note] mysqld: ready for connections.
  Version: '10.3.9-MariaDB-1:10.3.9+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
  </code></pre>