Unable to setup liquibase using docker image

Hello,

I’m using below command to generate changelog.
however the changelog.xml in /root/liquibase/changelog is empty.

{code}

docker run -v /root/liquibase/changelog:/liquibase/changelog liquibase:4.3.5 --classpath=/liquibase/changelog --url=“jdbc:mysql://10.x.x.x:3306/testdb?useSSL=FALSE” --driver=“com.mysql.cj.jdbc.Driver” --username=“username” --password=‘password’ --changeLogFile=changelog.xml generateChangeLog

Liquibase Community 4.3.5 by Datical

Starting Liquibase at 02:45:32 (version 4.3.5 #62 built at 2021-04-29 18:31+0000)
BEST PRACTICE: The changelog generated by diffChangeLog/generateChangeLog should be inspected for correctness and completeness before being deployed.

Liquibase command ‘generateChangeLog’ was executed successfully.

{code}

Hi @lq-user

I haven’t tried this but may be you could give this a try and check if this helps.
Try using options:
--includeSchema=true and --schemas=your_schema_name
in your generateChangelog command. These options works in PostgreSQL DB for me.

Please let us know the results.

Thanks!
Rakhi Agrawal

Thanks @rakhi

the container exits immediately , hence i don’t know where to check the changelog file contents

Any suggestions?

docker run --rm -v /root/liquibase/changelog:/liquibase/changelog liquibase:4.3.5 --url=“jdbc:mysql://10.x.x.x:3306/dbname” --driver=“com.mysql.cj.jdbc.Driver” --username=“username” --password=‘password’ --defaultSchemaName=performance_schema --changeLogFile=test.xml --logLevel INFO --includeSchema=true --schemas=dbname generateChangeLog

####################################################
Starting Liquibase at 06:31:12 (version 4.3.5 #62 built at 2021-04-29 18:31+0000)
BEST PRACTICE: The changelog generated by diffChangeLog/generateChangeLog should be inspected for correctness and completeness before being deployed.
[2021-06-03 06:31:14] INFO [liquibase.diff] changeSets count: 3
[2021-06-03 06:31:14] INFO [liquibase.diff] test.xml does not exist, creating and adding 3 changesets.
Liquibase command ‘generateChangeLog’ was executed successfully.

You can check the contents inside /liquibase/changelog volume I think. I have never really run liquibase with docker so can’t guarantee this.

But I found something which will help get the file created on local. This can help you confirm if the file has correct contents. Please read this doc.

If you have a local c:\projects\my-project\src\main\resources\com\example\changelogs\root.changelog.xml file, you can run:

docker run --rm -v c:\projects\my-project\src\main\resources:/liquibase/changelog 
--changeLogFile=com/example/changelogs/root.changelog.xml update

Hope this helps in some way.

Thanks,
Rakhi Agrawal

1 Like

checked this article https://rominirani.com/docker-on-windows-mounting-host-directories-d96f3f056a2c
it helped to log into the container

{coode}
$ ls -lah
total 984K
drwxr-xr-x. 2 root root 94 Jun 3 06:20 .
drwxr-xr-x. 1 liquibase root 40 Jun 3 06:45 …
-rwxrwxrwx. 1 root root 0 Jun 1 04:22 changelog.sql
-rwxrwxrwx. 1 root root 0 Jun 3 04:58 cl.sql
-rwxrwxrwx. 1 root root 0 Jun 1 04:28 cl.xml
-rwxr-xr-x. 1 root root 984K Nov 20 2019 mysql-connector-java-5.1.48.jar
{code}

so now i tried

docker run --rm -v /root/liquibase/changelog:/liquibase/changelog liquibase:4.3.5 --url=“jdbc:mysql://10.x.x.x:3306/dbname” --driver=“com.mysql.cj.jdbc.Driver” --username=“username” --password=‘password’ --defaultSchemaName=performance_schema --changeLogFile=/liquibase/changelog/test.xml --logLevel INFO --includeSchema=true --schemas=dbname generateChangeLog

Starting Liquibase at 06:52:47 (version 4.3.5 #62 built at 2021-04-29 18:31+0000)
BEST PRACTICE: The changelog generated by diffChangeLog/generateChangeLog should be inspected for correctness and completeness before being deployed.
[2021-06-03 06:52:48] INFO [liquibase.diff] changeSets count: 0
[2021-06-03 06:52:48] INFO [liquibase.diff] No changesets to add.
Unexpected error running Liquibase: java.io.FileNotFoundException: /liquibase/changelog/test.xml (Permission denied)
For more information, please use the --logLevel flag
[2021-06-03 06:52:48] SEVERE [liquibase.integration] Unexpected error running Liquibase: java.io.FileNotFoundException: /liquibase/changelog/test.xml (Permission denied)
liquibase.exception.LiquibaseException: liquibase.command.CommandExecutionException: java.io.FileNotFoundException: /liquibase/changelog/test.xml (Permission denied)
at liquibase.integration.commandline.CommandLineUtils.doGenerateChangeLog(CommandLineUtils.java:251)
at liquibase.integration.commandline.Main.doMigration(Main.java:1542)
at liquibase.integration.commandline.Main$1.lambda$run$0(Main.java:367)
at liquibase.Scope.lambda$child$0(Scope.java:160)
at liquibase.Scope.child(Scope.java:169)
at liquibase.Scope.child(Scope.java:159)
at liquibase.Scope.child(Scope.java:138)
at liquibase.integration.commandline.Main$1.run(Main.java:366)
at liquibase.integration.commandline.Main$1.run(Main.java:196)
at liquibase.Scope.child(Scope.java:169)
at liquibase.Scope.child(Scope.java:145)
at liquibase.integration.commandline.Main.run(Main.java:196)
at liquibase.integration.commandline.Main.main(Main.java:158)
Caused by: liquibase.command.CommandExecutionException: java.io.FileNotFoundException: /liquibase/changelog/test.xml (Permission denied)
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:24)
at liquibase.integration.commandline.CommandLineUtils.doGenerateChangeLog(CommandLineUtils.java:249)
… 12 more
Caused by: java.io.FileNotFoundException: /liquibase/changelog/test.xml (Permission denied)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(Unknown Source)
at java.base/java.io.FileOutputStream.(Unknown Source)
at java.base/java.io.FileOutputStream.(Unknown Source)
at liquibase.diff.output.changelog.DiffToChangeLog.printNew(DiffToChangeLog.java:235)
at liquibase.diff.output.changelog.DiffToChangeLog$1.run(DiffToChangeLog.java:133)
at liquibase.Scope.lambda$child$0(Scope.java:160)
at liquibase.Scope.child(Scope.java:169)
at liquibase.Scope.child(Scope.java:159)
at liquibase.Scope.child(Scope.java:138)
at liquibase.diff.output.changelog.DiffToChangeLog.print(DiffToChangeLog.java:127)
at liquibase.diff.output.changelog.DiffToChangeLog.print(DiffToChangeLog.java:85)
at liquibase.command.core.GenerateChangeLogCommand.run(GenerateChangeLogCommand.java:74)
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:19)
… 13 more

Why does these two outputs differ:

docker run --rm -v /root/liquibase/changelog:/liquibase/changelog liquibase:4.3.5 --url=“jdbc:mysql://10.x.x.x:3306/dbname” --driver=“com.mysql.cj.jdbc.Driver” --username=“username” --password=‘password’ --defaultSchemaName=performance_schema --changeLogFile=test.xml --logLevel INFO --includeSchema=true --schemas=dbname generateChangeLog

[2021-06-03 06:31:14] INFO [liquibase.diff] changeSets count: 3
[2021-06-03 06:31:14] INFO [liquibase.diff] test.xml does not exist, creating and adding 3 changesets.

docker run --rm -v /root/liquibase/changelog:/liquibase/changelog liquibase:4.3.5 --url=“jdbc:mysql://10.x.x.x:3306/dbname” --driver=“com.mysql.cj.jdbc.Driver” --username=“username” --password=‘password’ --defaultSchemaName=performance_schema --changeLogFile=/liquibase/changelog/test.xml --logLevel INFO --includeSchema=true --schemas=dbname generateChangeLog

[2021-06-03 06:52:48] INFO [liquibase.diff] changeSets count: 0
[2021-06-03 06:52:48] INFO [liquibase.diff] No changesets to add.

*changeLogFile path is changed

I’ll suggest to try out the local copy of file once as I mentioned in one of the replies earlier. Let’s check what exactly are the contents of file.

With your second trial it seems it’s not able to create test.xml because of permission issues. However as you have tried in the first trial, it was able to find atleast some contents to be populated inside resultant changelog file and was able to create a test.xml file when it didn’t exist.

can you please eloboarte on the local file part?

when i tried to not use any path for changelogfile , its success but i cant find the file local nor in the container

eg:

docker run --rm -v /root/liquibase/changelog:/liquibase/changelog liquibase:4.3.5 --url=“jdbc:mysql://10.x.x.x:3306/dbname” --driver=“com.mysql.cj.jdbc.Driver” --username=“username” --password=‘password’ --defaultSchemaName=performance_schema --changeLogFile=.test.xml --logLevel INFO --includeSchema=true --schemas=dbname generateChangeLog

BEST PRACTICE: The changelog generated by diffChangeLog/generateChangeLog should be inspected for correctness and completeness before being deployed.
[2021-06-03 07:14:06] INFO [liquibase.diff] changeSets count: 3
[2021-06-03 07:14:06] INFO [liquibase.diff] .test.xml does not exist, creating and adding 3 changesets.
Liquibase command ‘generateChangeLog’ was executed successfully.

so issue is with permissions

i tried with user root option

docker run –user root -v …–changeLogFile=/liquibase/changelog/test.xml … generateChangeLog

inside the container

$ cd changelog

$ ls -lah
total 988K
drwxr-xr-x. 2 root      root  110 Jun  3 07:22 .
drwxr-xr-x. 1 liquibase root   40 Jun  3 06:45 ..
-rwxr-xr-x. 1 root      root 984K Nov 20  2019 mysql-connector-java-5.1.48.jar
-rw-r--r--. 1 root      root  625 Jun  3 07:22 test.xml

$ cat test.xml
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd"/>

I am facing the same issue, getting “/liquibase/changelog/output.xml (Permission denied)” error, with docker run command.
This is command I am using:
docker run --rm --net=“host” -v /home/administrator/liquibase/changelog:/liquibase/changelog liquibase/liquibase --url=“jdbc:sqlserver://xx.x.x.164:1433;databaseName=liquibasedb;integratedSecurity=false;” --driver=“com.microsoft.sqlserver.jdbc.SQLServerDriver” --changeLogFile=/home/administrator/liquibase/HR/changelog/procedures/changelog.xml --username=“sa” --password=“BxxxxZ” generateChangeLog

tried with root permission also, same issue.

Hi @cleanops .
When you use -v /home/administrator/liquibase/changelog:/liquibase/changelog you are mounting the filesystem /home… into /liquibase/changelog inside the container. So when liquibase goes to run, it executes inside the /liquibase folder inside the container.
This means for the changelog file in the container you would reference changelogFile in following way.
./changelog/<path_to_rest_of_directory_structure>
i.e. if I mount /home/administrator/liquibase/HR/changelog/ to /liquibase/changelog
you would find the file in ./changelog/procedures/changelog.xml
or
changeLogFile=./changelog/procedures/changelog.xml
I would also make sure that the user running the docker command has read/write permission to the /home/administrator/liquibase/HR/changelog directory structure.