Liquibase is a nightmare to use in docker environment

I cannot believe this, I mean, I’m sure I’m doing something wrong, but I can’t figure out how to make this work.

I have Spring/Docker project with this structure:

  • backend-primary
  • postgres-primary
  • backend-secondary
  • Postgres-secondary
  • zookeeper
  • kafka

Now,

  • if I run mvn liquibase:diff from inside backend-primary FOLDER: it fails because liquibase cannot resolve Docker internal network addresses (specifically it cannot find postgres-primary which is in another container).

  • If I run mvn liquibase:diff from inside backend-primary CONTAINER: it doesn’t work because there is no maven image inside there (and it’s against best practice to insert maven image inside a container).

  • I’ve also tried mounting liquibase image INSIDE backend-primary, but I can’t use it cause ENTRYPOINT there is java -jar app.jar

The hell am I supposed to use a damn liquibase:diff in this environment ?

Hey @RiccardoPepe93. Thanks for joining the forums.

Unfortunately there’s not enough information here to clearly understand what you are trying to accomplish. A few questions:

  • What’s your use case? Are you working in a dev environment and you want to use liquibase:diff to capture changes to be propagated to other environments? Are you running it in a production environment to detect drift in the schema configuration? Knowing what you’re trying to accomplish would be very helpful.
  • Have you mapped your database ports to ports on the host system so a process outside of your Docker network can access them?
  • What specific errors are you getting from Liquibase when you execute it?

When I work in containerized app environments I typically don’t rely on maven for operational concerns. I use the Liquibase Docker container and the CLI to run my jobs.

Hi, thanks for yous answer, this was actually more a (wrong) reporting post about Liquibase not being easy to setup in a Docker/Spring environment. I posted the actual “help requests” on Stack Overflow and here in Liquibase Developement (not even sure it was the right place to do, but seemed the best).

While it being a bit complex (I’m still having trouble with version mismatching between dependencies) the problem I was having was not related to liquibase (I thought it was because only when using liquibase it was rising, but it wasn’t).

Basically, I had a postgres installed on my local machine and one in my docker system: when using mvn liquibase:diff it was trying to connect to the one on my local machine and not the one in docker (they were listening on the same port).

Since we’re at it, can you help me with this ?
I’m having incompatibility problems between liquibase and other dependencies. This is what I get when using mvn liquibase:diff

[WARNING] HHH000505: Ignoring ServiceConfigurationError caught while trying to instantiate service 'interface org.hibernate.boot.model.FunctionContributor'.
java.util.ServiceConfigurationError: org.hibernate.boot.model.FunctionContributor: org.hibernate.envers.boot.internal.FunctionContributorImpl not a subtype
[WARNING] HHH000505: Ignoring ServiceConfigurationError caught while trying to instantiate service 'interface org.hibernate.boot.spi.AdditionalMappingContributor'.
java.util.ServiceConfigurationError: org.hibernate.boot.spi.AdditionalMappingContributor: org.hibernate.envers.boot.internal.AdditionalMappingContributorImpl not a subtype
[WARNING] HHH000505: Ignoring ServiceConfigurationError caught while trying to instantiate service 'interface org.hibernate.boot.model.TypeContributor'.
java.util.ServiceConfigurationError: org.hibernate.boot.model.TypeContributor: org.hibernate.envers.boot.internal.TypeContributorImpl not a subtype

[WARNING] HHH000505: Ignoring ServiceConfigurationError caught while trying to instantiate service 'interface org.hibernate.service.spi.ServiceContributor'.
java.util.ServiceConfigurationError: org.hibernate.service.spi.ServiceContributor: org.hibernate.envers.boot.internal.EnversServiceContributor not a subtype
[WARNING] HHH000505: Ignoring ServiceConfigurationError caught while trying to instantiate service 'interface org.hibernate.boot.registry.selector.StrategyRegistrationProvider'.
java.util.ServiceConfigurationError: org.hibernate.boot.registry.selector.StrategyRegistrationProvider: org.hibernate.envers.boot.internal.AuditStrategyRegistrationProvider not a subtype
[WARNING] HHH000505: Ignoring ServiceConfigurationError caught while trying to instantiate service 'interface org.hibernate.boot.registry.selector.StrategyRegistrationProvider'.
java.util.ServiceConfigurationError: org.hibernate.boot.registry.selector.StrategyRegistrationProvider: org.hibernate.envers.boot.internal.ModifiedColumnNamingStrategyRegistrationProvider not a subtype
[WARNING] HHH000505: Ignoring ServiceConfigurationError caught while trying to instantiate service 'interface org.hibernate.integrator.spi.Integrator'.
java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: org.hibernate.envers.boot.internal.EnversIntegrator not a subtype

This is my pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.5.0</version>
		<relativePath/>
	</parent>

	<groupId>com.starcrest</groupId>
	<artifactId>backend-primary</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>backend-primary</name>
	<description>Main backend for Starcrest central server</description>

	<properties>
		<java.version>21</java.version>
		<hibernate.version>6.2.7.Final</hibernate.version>
	</properties>

	<dependencies>
		<!-- SPRING -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.hibernate.orm</groupId>
					<artifactId>hibernate-envers</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-mail</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-configuration-processor</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<!-- KAFKA -->
		<dependency>
			<groupId>org.springframework.kafka</groupId>
			<artifactId>spring-kafka</artifactId>
		</dependency>
		<!-- LOMBOK -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<!-- POSTGRES -->
		<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<scope>runtime</scope>
		</dependency>
		<!-- SECURITY -->
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-crypto</artifactId>
		</dependency>
		<dependency>
			<groupId>io.jsonwebtoken</groupId>
			<artifactId>jjwt-api</artifactId>
			<version>0.12.6</version>
		</dependency>
		<dependency>
			<groupId>io.jsonwebtoken</groupId>
			<artifactId>jjwt-impl</artifactId>
			<version>0.12.6</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>io.jsonwebtoken</groupId>
			<artifactId>jjwt-jackson</artifactId>
			<version>0.12.6</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>com.github.vladimir-bukhtoyarov</groupId>
			<artifactId>bucket4j-core</artifactId>
			<version>7.6.0</version>
		</dependency>
		<!-- GSON -->
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
			<version>2.10.1</version>
		</dependency>
		<!-- LIQUIBASE -->
		<dependency>
			<groupId>org.liquibase</groupId>
			<artifactId>liquibase-core</artifactId>
			<version>4.27.0</version>
		</dependency>
		<dependency>
			<groupId>org.liquibase.ext</groupId>
			<artifactId>liquibase-hibernate6</artifactId>
			<version>4.27.0</version>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-autoconfigure</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<annotationProcessorPaths>
						<path>
							<groupId>org.springframework.boot</groupId>
							<artifactId>spring-boot-configuration-processor</artifactId>
						</path>
						<path>
							<groupId>org.projectlombok</groupId>
							<artifactId>lombok</artifactId>
						</path>
					</annotationProcessorPaths>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<argLine>-XX:+EnableDynamicAgentLoading</argLine>
				</configuration>
			</plugin>
			<!-- LIQUIBASE -->
			<plugin>
				<groupId>org.liquibase</groupId>
				<artifactId>liquibase-maven-plugin</artifactId>
				<version>4.27.0</version>
				<configuration>
					<propertyFile>src/main/resources/liquibase.properties</propertyFile>
					<referenceUrl>hibernate:spring:com.starcrest.backend_primary.entity?dialect=org.hibernate.dialect.PostgreSQLDialect</referenceUrl>
					<changeLogFile>src/main/resources/database/changelog/db.changelog-master.yaml</changeLogFile>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>