Docker Compose:带有mysql的SpringBoot应用程序:8

时间:2018-04-27 10:39:23

标签: docker docker-compose dockerfile

下面是我的docker-compose.yml,它组成了两个docker文件:

  1. mysql.dockerfile

    FROM mysql:8  
    ADD DockerImages/mysql /docker-entrypoint-initdb.d/
    
  2. springapp.dockerfile

    FROM maven:3.5-jdk-8 <br>
    ADD target/users-mysql.jar users-mysql.jar<br>
    ENTRYPOINT ["/usr/bin/java"]<br>
    CMD ["-jar", "users-mysql.jar"]<br>
    VOLUME /var/lib/spring-cloud/config-repo
    
  3. 搬运工-compose.yml

    版本:'3'

    services:
    
      springapp:
        build: 
          context: . 
          dockerfile: springapp.dockerfile
        expose:
          - "8888"
        ports:
          - 8888:8888
        links:
          - mysqldb:mysqldb
        networks:
          - spring-demo-network
        depends_on:
          - mysqldb      
        environment:
          - DATABASE_HOST=mysqldb
          - DATABASE_USER=gl_user
          - DATABASE_PASSWORD=global@123
          - DATABASE_NAME=test_db
    
      mysqldb:
        build: 
          context: . 
          dockerfile: mysql.dockerfile
        ports:
          - 3306:3306
        container_name : mysql-standalone
        networks:
          - spring-demo-network
        environment:
          MYSQL_DATABASE: test_db
          MYSQL_USER: gl_user
          MYSQL_PASSWORD: global@123
          MYSQL_ROOT_PASSWORD: root
          MYSQL_ROOT_HOST: '%'         
    
    networks:
      spring-demo-network:
        driver: bridge
    
  4. 我无法连接到数据库,因此会抛出多个错误 错误:

    • java.sql.SQLException:null,来自服务器的消息:“主机'172.18.0.3' 不允许连接到这个MySQL服务器“
    • 引起:java.net.ConnectException:连接被拒绝(连接 拒绝)

0 个答案:

没有答案