0

I'm using docker-compose to run MariaDB and it is working fine. I am fetching jasper server and maria DB docker images and running them. When I telnet the jasper server image, it responds correctly, but when I telnet to MariaDB, it says:

telnet localhost 3306
Trying ::1...
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

What I might be doing wrong?
Here is the output of sudo docker ps -a:

CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS                                           NAMES
9e759f106006        bitnami/jasperreports:7   "/app-entrypoint.sh …"   21 minutes ago      Up 21 minutes       0.0.0.0:9093->8080/tcp, 0.0.0.0:443->8443/tcp   ceyedev_jasperreports_1
9242e52f6af8        bitnami/mariadb:10.3      "/opt/bitnami/script…"   21 minutes ago      Up 21 minutes       3306/tcp                                        ceyedev_mariadb_1

Here is my docker compose file:

version: '2'
services:
  mariadb:
    image: 'bitnami/mariadb:10.3'
    environment:
      - MARIADB_USER=bn_jasperreports
      - MARIADB_DATABASE=bitnami_jasperreports
      - ALLOW_EMPTY_PASSWORD=yes
    volumes:
      - 'mariadb_data:/bitnami'
  jasperreports:
    image: 'bitnami/jasperreports:7'
    environment:
      - MARIADB_HOST=mariadb
      - MARIADB_PORT_NUMBER=3306
      - JASPERREPORTS_DATABASE_USER=bn_jasperreports
      - JASPERREPORTS_DATABASE_NAME=bitnami_jasperreports
      - ALLOW_EMPTY_PASSWORD=yes
    ports:
      - '9093:8080'
      - '443:8443'
    volumes:
      - 'jasperreports_data:/bitnami'
    depends_on:
      - mariadb
volumes:
  mariadb_data:
    driver: local
  jasperreports_data:
    driver: local 
Marc Sances
  • 2,402
  • 1
  • 19
  • 34
Jamshaid
  • 370
  • 2
  • 11
  • 40

1 Answers1

1

You have to open the ports in your Docker compose file (that thing you posted is called a Docker Compose file, not Dockerfile which is the one containing the commands to build a Docker image).

In the mariadb section make it like this:

services:
  mariadb:
    image: 'bitnami/mariadb:10.3'
    environment:
      - MARIADB_USER=bn_jasperreports
      - MARIADB_DATABASE=bitnami_jasperreports
      - ALLOW_EMPTY_PASSWORD=yes
    volumes:
      - 'mariadb_data:/bitnami'
    ports:
      - 3306

This way, the 3306 port of MariaDB will be exposed to your local computer. This means:

  • that you may access MariaDB through the 3306 port
  • that ANYONE with direct network access to your computer (i.e. local IP address) will be able to access MariaDB through port 3306.

Bear in mind those two things regarding your system security.

Marc Sances
  • 2,402
  • 1
  • 19
  • 34
  • Docker compose ``ports`` instruction actually exposes and **publishes** (binds) a container port to the docker host (Unlike ``expose`` instruction, which exposes ports without publishing them, i.e. only internally between containers). So yes, the answer should indeed fix the problem (did you try it before commenting...?). – Marc Sances Oct 13 '20 at 07:14
  • My apologies, you are absolutely right. I had forgotten about this dual port/expose feature in compose file. Thanks for reminding me. – Zeitounator Oct 13 '20 at 07:18
  • @MarcSances thanks for the answer. I had figured that out. One thing, is exposing the database port causes security risks like this one? – Jamshaid Oct 13 '20 at 08:15
  • The security risks are the ones exposed in the answer. It mostly means that the 3306 container port will be reachable in your Docker host. Usually you would prefer to isolate this port in production so only consumer services such as an API or jasper would be able to access the database. However, if your machine runs in a private network, there is no huge security concern. – Marc Sances Oct 13 '20 at 08:24