Liquibase Docker generateChangeLog Failed to create parent directories for file /liquibase/changelog/changelog.xml

I know there have been couple of discussions on this topic and I have followed through them–

  1. postgresql - Liquibase via Docker - Changelog is not written to disk - Stack Overflow
  2. [Unable to setup liquibase using docker image - General Discussion - Liquibase]
    (Unable to setup liquibase using docker image - #12 by MikeOlivas),

But my issues still persist, that is I still can not generate changelog to my local linux system.

liquibase.docker.properties
classpath: /liquibase/changelog
url: jdbc:postgresql://rdsurl:1234/testdb?currentSchema=public
changeLogFile: changelog.xml
username: testuser
password: TestPwd

  1. The following command run successfully and if I access the liquibase container, I can see changelog.xml put in the liquibase container /liquibase directory . But I can’t access from the local host;
    docker run --rm --net=“host” -v /home/user/docker/init-liquibase/changelog:/liquibase/changelog liquibase/liquibase --defaultsFile=/liquibase/changelog/liquibase.docker.properties –changeLogFile=changelog.xml generateChangeLog --log-level flag

  2. If I follow the links above to put absolute path in front the changlog.xml, I get error.
    docker run --rm --net=“host” -v /home/user/docker/init-liquibase/changelog:/liquibase/changelog liquibase/liquibase --defaultsFile=/liquibase/changelog/liquibase.docker.properties –changeLogFile=/liquibase/changelog/changelog.xml generateChangeLog --log-level flag

Error log–
BEST PRACTICE: The changelog generated by diffChangeLog/generateChangeLog should be inspected for correctness and completeness before being deployed. Some database objects and their dependencies cannot be represented automatically, and they may need to be manually updated before being deployed.
[2023-02-24 02:09:15] INFO [liquibase.database] Set default schema name to public
[2023-02-24 02:09:16] INFO [liquibase.diff] changeSets count: 43
[2023-02-24 02:09:16] INFO [liquibase.diff] liquibase/changelog/changelog.xml does not exist, creating and adding 43 changesets.
[2023-02-24 02:09:16] WARNING [liquibase.resource] Failed to create parent directories for file /liquibase/changelog/changelog.xml
[2023-02-24 02:09:16] SEVERE [liquibase.integration] /liquibase/changelog/changelog.xml
liquibase.exception.CommandExecutionException: liquibase.exception.LiquibaseException: liquibase.exception.CommandExecutionException: java.nio.file.AccessDeniedException: /liquibase/changelog/changelog.xml
at liquibase.command.CommandScope.execute(CommandScope.java:186)
at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:55)
at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:24)
at picocli.CommandLine.executeUserObject(CommandLine.java:2041)
at picocli.CommandLine.access$1500(CommandLine.java:148)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
at picocli.CommandLine.execute(CommandLine.java:2170)
at liquibase.integration.commandline.LiquibaseCommandLine.lambda$execute$1(LiquibaseCommandLine.java:352)
at liquibase.Scope.child(Scope.java:189)

Hi @karenxbai Thanks for joining the community.
Try changing your changelog file name to
–changeLogFile=./changelog/changelog.xml

In the container liquibase runs from /liquibase
so that means that in the container the changelog directory is in ./changelog
or /liquibase/changelog.
Outside of the container (your filesystem) it will be your mount point.
/home/user/docker/init-liquibase/changelog

Visual way to the look at it.
home/user/docker/init-liquibase/changelog ← your local filesystem

In the container
/liquibase ← where liquibase binary runs when you issue liquibase commands (non accessbile after the commands run)
/liquibase/changelog ← anything mounted here (using -v parameter) will be accessible after liquibase finishes

When you use liquibase --changelog-file=somename.xml
The container will place the file in the container in the /liquibase folder which cannot be accessed post run
Hopefully that clarifies things.

@MikeOlivas Thanks a lot for the reply and instruction.
But I still got similar errors after use changeLogFile=./changelog/changelog.xml:
See the below updated command and respective error. Why there is always an action try to create parent directory of the “changeLogFile”?
I know that the container /liquibase/changelog is accessible since the defaultsFile=/liquibase/changelog/liquibase.docker.properties can be accssed.

CMD–
docker run --rm --net=“host” -v /home/user/docker/init-liquibase/changelog:/liquibase/changelog liquibase/liquibase --defaultsFile=/liquibase/changelog/liquibase.docker.properties --changeLogFile=./changelog/changelog.xml generateChangeLog --log-level flag > log022401 2>&1

error–
[2023-02-24 18:41:04] INFO [liquibase.diff] ./changelog/changelog.xml does not exist, creating and adding 43 changesets.
[2023-02-24 18:41:04] WARNING [liquibase.resource] Failed to create parent directories for file changelog/changelog.xml
[2023-02-24 18:41:04] SEVERE [liquibase.integration] changelog/changelog.xml
liquibase.exception.CommandExecutionException: liquibase.exception.LiquibaseException: liquibase.exception.CommandExecutionException: java.nio.file.AccessDeniedException: changelog/changelog.xml