Search code examples
dockerdocker-composejasperserver

can't connect between my two containers with docker-compose


I'm trying to connect two containers with docker compose. this I can succesfully do this when working on my own machine, but not when I try to run the same docker-compose.yml file on a kitty enviroment.

Any ideas what the problem could be, since it works on my own machine?

The error that I get looks like this:

Successfully built 8970545ddd5e
Starting postgres_db
Starting jasper.mobylife.com
Attaching to jasper.mobylife.com, postgres_db
jasper.mobylife.com | psql: could not connect to server: Connection refused
jasper.mobylife.com |   Is the server running on host "postgres_db" (172.19.0.3) and accepting
jasper.mobylife.com |   TCP/IP connections on port 5432?
jasper.mobylife.com | Waiting for PostgreSQL...
postgres_db      | 2019-05-13 13:22:16.087 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_db      | 2019-05-13 13:22:16.087 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_db      | 2019-05-13 13:22:16.088 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_db      | 2019-05-13 13:22:16.097 UTC [20] LOG:  database system was shut down at 2019-05-13 13:22:02 UTC
postgres_db      | 2019-05-13 13:22:16.100 UTC [1] LOG:  database system is ready to accept connections
jasper.mobylife.com | psql: could not connect to server: Connection refused
jasper.mobylife.com |   Is the server running on host "postgres_db" (172.19.0.3) and accepting
jasper.mobylife.com |   TCP/IP connections on port 5432?
jasper.mobylife.com | Waiting for PostgreSQL...
jasper.mobylife.com | psql: could not connect to server: Connection refused
jasper.mobylife.com |   Is the server running on host "postgres_db" (172.19.0.3) and accepting
jasper.mobylife.com |   TCP/IP connections on port 5432?
jasper.mobylife.com | Waiting for PostgreSQL...

my docker-compose.yml:

# Copyright (c) 2016. TIBCO Software Inc.
# This file is subject to the license terms contained
# in the license file that is distributed with this file.
# version: 6.3.0-v1.0.4

version: '2'

# network used by both JasperReports Server and PostgreSQL containers
networks:
  default:
    ipam:
      config:
        - subnet: "192.168.5.1/24"
  jasper:
    external:
      name: jasper

services:
  jasperserver:
    build: .
    # expose port 8082 and bind it to 8080 on host
    ports:
      - "8082:8080"
      - "8443:8443"
    # set depends on js_database service
    # point to env file with key=value entries 
    container_name: jasper.mobylife.com
    env_file: .env
    # setting following values here will override settings from env_file
    environment:
      - DB_HOST=postgres_db
      - DB_PASSWORD=12345678
    volumes:
      - jrs_webapp:/usr/local/tomcat/webapps/jasperserver-pro
      - jrs_license:/usr/local/share/jasperreports-pro/license 
      - jrs_customization:/usr/local/share/jasperreports-pro/customization
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
      # for Mac OS you may want to define local path for volume mounts. 
      # Note that defining path for a named volume is not supported 
      # by Compose. For example:
      # - /some-local-path:/usr/local/tomcat/webapps/jasperserver-pro
      # - ~/jasperreports-pro/license:/usr/local/share/jasperreports-pro/license
      # - /tmp/customization:/usr/local/share/jasperreports-pro/customization
    networks:
      - default
      - jasper

  etel-postgres:
    image: postgres:10.3
    container_name: postgres_db
    hostname: postgres_db
    environment:
      - POSTGRES_PASSWORD=12345678
    ports:
      - "5432:5432"
    volumes:
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
      - db.volume:/var/lib/postgresql
    networks:
      - default
      - jasper



volumes:
  jrs_webapp:
    driver: local
  jrs_license:
  jrs_customization:
  init.sql:
  db.volume:
  db.volume.data:


Dockerfile:

# Copyright (c) 2016. TIBCO Software Inc.
# This file is subject to the license terms contained
# in the license file that is distributed with this file.
# version: 6.3.0-v1.0.4
FROM tomcat:8.0-jre8

# Copy jasperreports-server-<ver> zip file from resources dir.
# Build will fail if file not present.
COPY resources/jasperreports-server*zip /tmp/jasperserver.zip
##edited out actual proxy
 ENV HTTP_PROXY=http://*.**.***.**:*****\
     http_proxy=http://*.**.***.**:*****\
     HTTPS_PROXY=https://*.**.***.**:*****\
     https_proxy=https://*.**.***.**:***** 

RUN apt-get update && apt-get install -y postgresql-client unzip xmlstarlet && \
    rm -rf /var/lib/apt/lists/* && \
    unzip /tmp/jasperserver.zip -d /usr/src/ && \
    mv /usr/src/jasperreports-server-* /usr/src/jasperreports-server && \
    mkdir -p /usr/local/share/jasperreports-pro/license





# Set default environment options.
ENV CATALINA_OPTS="${JAVA_OPTIONS:--Xmx2g -XX:+UseParNewGC \
    -XX:+UseConcMarkSweepGC} \
    -Djs.license.directory=${JRS_LICENSE:-/usr/local/share/jasperreports-pro/license}"


# Expose ports. Note that you must do one of the following:
# map them to local ports at container runtime via "-p 8080:8080 -p 8443:8443"
# or use dynamic ports.
EXPOSE ${HTTP_PORT:-8081} ${HTTPS_PORT:-8443}



COPY scripts/entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

# Default action executed by entrypoint script.
CMD ["run"]

my solution is heavily based on this project: https://github.com/TIBCOSoftware/js-docker


Solution

  • Turns out the default network was already running on the enviroment, but for some reason didn't work properly. Restarting the default network then fixed the problem