错误:主机数据库上无法访问端口3306

时间:2019-08-06 18:43:28

标签: mysql docker docker-compose jasperserver

我正在尝试使用ubuntu上的docker-compose文件将jasper-reports服务器与MySQL数据库连接。这里我们为jasper服务器和MySQL编写了单独的docker文件。在执行docker-compose时,我们得到了类似port 3306 is not reachable at host db的错误。这是我的MySQL容器的服务名称。

以下是我的docker-compose.yaml配置文件,MySQL的docker文件和default_master.properties。

FROM ubuntu:16.04
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server && \
    sed -i "s/127.0.0.1/0.0.0.0/g" /etc/mysql/mysql.conf.d/mysqld.cnf && \
    mkdir -p /var/lib/mysql && \
    mkdir -p /var/run/mysqld && \
    mkdir -p /var/log/mysql && \
    chown -R mysql:mysql /var/lib/mysql && \
    chown -R mysql:mysql /var/run/mysqld && \
    chown -R mysql:mysql /var/log/mysql
VOLUME ["/var/lib/mysql"]
EXPOSE 3306
CMD ["mysqld_safe"]

default_master.properties文件

# Application Server Settings
appServerType=tomcat
# Tomcat app server root dir
appServerDir=/usr/local/tomcat
# database type
dbType=mysql
# database location and connection settings
dbHost=db
dbUsername=root
dbPassword=mysql
# additional database parameters
# (uncomment these if you want non-default settings)
dbPort=3306
# JasperServer db name, sample db names
js.dbName=jasperserverdb

docker-compose.yaml

version: '3.3'
services:
  db:
    build:
      context: .
      dockerfile: mysql-docker
    image: 'mysql:latest'
    container_name: mysql_jasperserver
    environment:
      - MYSQL_ROOT_PASSWORD=mysql
    ports:
      - '3306:3306'
    volumes:
      - 'mysqldb:/var/lib/mysql'
  jasperreports:
    build: .
    image: 'jasper:latest'
    container_name: jasperserver
    environment:
      - DB_TYPE=mysql
      - DB_HOST=db
      - DB_PORT=3306
      - DB_USER=root
      - DB_PASSWORD=mysql
    ports:
      - '80:8080'
      - '443:8443'
    volumes:
      - jasperserver-import:/jasperserver-import
    depends_on:
      - db
volumes:
  mysqldb:
    driver: local
  jasperserver-import:
    driver: local

您可以看到以下快照中遇到的确切错误。

gen-config:
     [echo] Regen config files if they have already been cleaned:
     [echo] currentConf= /opt/jasperserver-pro/buildomatic/build_conf/default
     [echo] chkIfPackageManagedTomcat: check if package managed tomcat
     [echo] Tomcat DBCP Factory: com.jaspersoft.jasperserver.tomcat.jndi.JSCommonsBasicDataSourceFactory
     [echo] chkAndSetLocaleDbSettings: parse: scripts.properties for db commands

test-ce-all-props:
     [echo] Checking properties:
     [echo]   dbType=mysql
     [echo]   dbHost=db
     [echo]   dbUsername=root
     [echo]   dbPassword=**********
     [echo]   dbPort=3306
     [echo]   js.dbName=jasperserverdb
     [echo]   sugarcrm.dbName=sugarcrm
     [echo]   foodmart.dbName=foodmart
     [echo]   webAppNameCE=jasperserver
     [echo]   appServerType=tomcat
     [echo]   appServerDir=/usr/local/tomcat

check-dbtype-ce:

test-appServerType-ce:

do-install-upgrade-test:
     [echo] Checking DBMS host and port:
     [echo] About to validate port: db

 BUILD FAILED
 /opt/jasperserver-pro/buildomatic/bin/validation.xml:489: The following error occurred while executing this line:
 /opt/jasperserver-pro/buildomatic/bin/validation.xml:246: The following error occurred while executing this line:
 /opt/jasperserver-pro/buildomatic/bin/validation.xml:295: Error: port 3306 is not reachable at host db

有人可以建议我解决此问题吗?

0 个答案:

没有答案