Docker + MySQL + Springboot-无法通过docker compose运行(无法连接)

时间:2019-11-06 07:28:18

标签: mysql spring spring-boot docker docker-compose

我正在通过docker进行部署,并希望在同一网络中的容器内使用Mysql,但无法正常工作-错误 引起原因:com.mysql.cj.exceptions.CJCommunicationsException: 通讯链接失败

我已附上支持文件。谁能帮忙。

我尝试了几种方法,将mysql的映像更改为mysql / server,尝试设置等待脚本,但没有一个对我有用

------ >>>>>> Docker-compose.yml

df = pd.DataFrame(techlist)

results = df['recordnum'].to_list()

---- >>>>>> DockerFile

version: '3.2'
services:
  db-new:
    container_name: mysql
    image: mysql
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_DATABASE: test
      MYSQL_USER: root
      MYSQL_PASSWORD: root
      MYSQL_ROOT_PASSWORD: root
      MYSQL_ROOT_HOST: '%'
    volumes:
      - db-data:/var/lib/mysql
    networks:
      - myNetwork-new

  backend:
    container_name: my-backend
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - /data/app
    ports:
      - "8090:8090"
    restart: always
    depends_on:
      - db-new
    networks:
      - myNetwork-new

#Volumes
volumes:
  db-data:

networks:
  myNetwork-new:
    driver: bridge

--------- >>>> application.properties

# Maven build container
FROM maven:3.5.2-jdk-8-alpine

# Add Maintainer Info
MAINTAINER Rajat Gupta <rajat@gmail.com>

WORKDIR /usr/src/java-code

COPY . /usr/src/java-code/

# command to build the jar
RUN mvn package

#setting the working directory
WORKDIR /usr/src/java-app

#copying the jar files
RUN cp /usr/src/java-code/target/*.jar ./app.jar

#command to execute the jar file
#CMD ["/usr/src/java-app/wait-for-it.sh", "db:3306", "-t", "6000", "--","java", "-jar", "app.jar"]
CMD ["java", "-jar", "app.jar"]

我希望输出是与Mysql容器连接的spring-boot应用程序

0 个答案:

没有答案