无法通过dockerrun.aws.json文件将springboot容器与mysql容器连接

时间:2018-12-08 00:00:21

标签: spring-boot docker dockerfile amazon-elastic-beanstalk

我已经尝试将它固定几天了,我想我只是搞砸了端口映射的工作方式。本质上,我有一个springboot应用程序,其中将jar注入docker容器并将其链接到mysql容器。如果我在本地运行,则可以使其正常运行,但是在尝试将其部署到AWS Elasticbeanstalk之前,我正在尝试使其在“ eb local run”中运行。我在运行eb local run时遇到的错误是“ ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

在冗长的堆栈跟踪中,我看到如下内容: Caused by: java.net.ConnectException: Connection refused (Connection refused) main] o.s.b.a.orm.jpa.DatabaseLookup : Unable to determine jdbc url from datasource

我已经尝试过审查类似这里的答案,我可以肯定列出我遇到的问题,但是似乎找不到我要解决的地方。 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

这是我的jar中的application.properties:

#Change the port that springboot starts up on
server.port=80

#For creating everything from scratch
spring.jpa.hibernate.ddl-auto=create

#For keeping the state of previous container
#spring.jpa.hibernate.ddl-auto=none

#For performance monitoring of hibernate should be false for any production release
#spring.jpa.properties.hibernate.generate_statistics=true

#url for local testing
spring.datasource.url = jdbc:mysql://mysql-docker-container:3306/maindb?useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false

#url for deployment
spring.datasource.url = jdbc:mysql://elasticbeanstalk_mysqldockercontainer_1:3306/maindb?useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false

#For Local Testing
#spring.datasource.url = jdbc:mysql://localhost:3306/maindb?useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false


spring.datasource.username = root
spring.datasource.password = password

# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

这是我在执行eb local run之前正在构建的Dockerfile(skyboundtrading只是我用Java和mysqlcli加载的ubuntu映像)

FROM skyboundtrading
VOLUME /tmp
EXPOSE 80
ADD target/skyboundtrading-1.0-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]

这是在执行eb local run之前我正在使用的构建命令:

docker build -f ./skyboundtrading/Dockerfile -t skyboundtradingchild ./skyboundtrading

最后,这是eb local run命令正在使用的dockerrun.aws.json文件:

{
  "AWSEBDockerrunVersion": 2,
  "containerDefinitions": [
    {
      "name": "elasticbeanstalk_skyboundtradingchild_1",
      "image": "skyboundtradingchild",
      "memory": 128,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80
        }
      ],
      "links": [
        "elasticbeanstalk_mysqldockercontainer_1"
      ],
      "environment": [
        {
          "name": "MYSQL_ROOT_PASSWORD",
          "value": "password"
        }
      ]
    },
    {
      "name": "elasticbeanstalk_mysqldockercontainer_1",
      "image": "mysql:latest",
      "memory": 128,
      "portMappings": [
        {
          "hostPort": 3306,
          "containerPort": 3306
        }
      ],
      "environment": [
        {
          "name": "MYSQL_USERNAME",
          "value": "root"
        },
        {
          "name": "MYSQL_ROOT_PASSWORD",
          "value": "password"
        },
        {
          "name": "MYSQL_DATABASE",
          "value": "maindb"
        }
      ]
    }
  ]
}

在运行eb local run并启动失败后,出现我上面发布的错误,我将其作为我的Docker容器状态:

➜  CodeBase docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
85cb5620f81c        mysql:latest        "docker-entrypoint.s…"   15 minutes ago      Up 15 minutes       0.0.0.0:3306->3306/tcp, 33060/tcp   elasticbeanstalk_elasticbeanstalkmysqldockercontainer1_1

➜  CodeBase docker ps -a
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS                           PORTS                                                                               NAMES
58d3e0bde90e        skyboundtradingchild   "java -jar app.jar"      15 minutes ago      Exited (1) 15 minutes ago                                                                                            elasticbeanstalk_elasticbeanstalkskyboundtradingchild1_1
85cb5620f81c        mysql:latest           "docker-entrypoint.s…"   15 minutes ago      Up 15 minutes                    0.0.0.0:3306->3306/tcp, 33060/tcp                                                   elasticbeanstalk_elasticbeanstalkmysqldockercontainer1_1


➜  CodeBase docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
skyboundtradingchild      latest              5a2e6e961c0a        16 minutes ago      639MB
<none>                    <none>              9df92435b273        25 minutes ago      639MB
skyboundtrading           latest              fcf5653a0bbc        5 days ago          597MB

任何帮助将不胜感激。我超级被这个迷住了...

0 个答案:

没有答案