xxljob docker compose deploy

xxljob docker compose deploy: could not create connection to database server

docker-compose.yaml file

version: '2'
services:

  xxl-job:
    container_name: xxl-job
    image: xuxueli/xxl-job-admin:2.3.1
    ports:
      - 8080:8080
    links:
      - mysql
    depends_on:
      - mysql
    environment:
      PARAMS: '--spring.datasource.url=jdbc:mysql://mysql:3306/xxl_job?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=root --spring.datasource.password=root --xxl.job.accessToken=dasj2nd81jf9asjdkl5jk234'
    networks:
      - xxl_job_net

  mysql:
    container_name: mysql
    image: mysql
    restart: always
    ports:
      - 13306:3306
    volumes:
      - .:/docker-entrypoint-initdb.d
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: xxl_job
    networks:
      - xxl_job_net

networks:
  xxl_job_net:
    driver: bridge

>>> docker compose up
Could not create connection to database server
xxljob docker compose deploy_第1张图片


解决方案:
1 查询docker mysql ip address

>>> docker inspect mysql | grep IPAddress
# 172.18.0.2

2 替换docker-compose.yaml文件中 PARAMS spring.datasource.url值

--spring.datasource.url=jdbc:mysql://mysql:3306/xxl_job
替换为
--spring.datasource.url=jdbc:mysql://172.18.0.2:3306/xxl_job

3 docker compose up 连接成功

你可能感兴趣的:(dockermysql)