Liquibase is unable to connect to the database, when I am running liquibase against my database, I get the following error:
liquibase_1 | Starting Liquibase at 21:40:22 (version 4.23.1 #12042 built at 2023-08-10 13:48+0000)
liquibase_1 | Liquibase Version: 4.23.1
liquibase_1 | Liquibase Open Source 4.23.1 by Liquibase
liquibase_1 |
liquibase_1 | Unexpected error running Liquibase: Connection could not be created to jdbc:mysql://mysql_db:3307/patshala with driver com.mysql.cj.jdbc.Driver. Communications link failure
liquibase_1 |
liquibase_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
liquibase_1 | - Caused by: Connection refused
Below is my docker compose file, is there anything I am missing here?
version: '3.8'
services:
mysql_db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: patshala
MYSQL_USER: mysql
MYSQL_PASSWORD: password
volumes:
- ./db:/docker-entrypoint-initdb.d/
ports:
- "3307:3306"
networks:
- app-network
liquibase:
image: liquibase/liquibase:latest
command: ["--url=jdbc:mysql://mysql_db:3307/patshala", "--username=mysql", "--password=password", "--changeLogFile=/db/changelog/db.changelog.xml", "update"]
volumes:
- ./db:/liquibase/changelog
- ./mysql-connector-j-8.1.0.jar:/liquibase/lib/mysql-connector-j-8.1.0.jar
depends_on:
- mysql_db
networks:
- app-network
networks:
app-network:
driver: bridge
2
Answers
Based from the latest documentation of Liquibase, you need to create a Dockerfile in order to install the MySQL driver to Liquibase.
Reference: [MySQL Licensing Restriction] 1
You are exposing port
3307
to the host machine. Both liquibase and mysql are in the same networkapp-network
so if you use port 3307, liquibase could not connect to it. So: