【发布时间】:2021-07-26 13:10:09
【问题描述】:
我是 Docker 新手,我一直在尝试实现数据库(Postgresql)和 API(带有 liquibase 的 Spring Boot)的容器化。但是,似乎 liquibase 没有运行。请参阅以下内容供您参考。提前致谢。
application.properties:
spring.datasource.url=jdbc:postgresql://db:5432/demo
spring.datasource.username=compose-postgres
spring.datasource.password=compose-postgres
spring.jpa.hibernate.ddl-auto=none
spring.liquibase.change-log=classpath:db/liquibase-changelog.xml
docker-compose.yml:
version: '2'
services:
api:
image: 'docker-spring-boot-postgres:latest'
build:
context: .
container_name: api
depends_on:
- db
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/demo
- SPRING_DATASOURCE_USERNAME=compose-postgres
- SPRING_DATASOURCE_PASSWORD=compose-postgres
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
ports:
- "8080:8080"
db:
image: 'postgres:13.1-alpine'
container_name: db
environment:
- POSTGRES_USER=compose-postgres
- POSTGRES_PASSWORD=compose-postgres
- POSTGRES_DB=demo
Dockerfile:
FROM adoptopenjdk:11-jre-hotspot
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
liquibase-changelog.xml:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="https://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<include file="changelog/01-createTableUser-changelog.sql" relativeToChangelogFile="true"/>
<!-- more <include> tags go here -->
</databaseChangeLog>
liquibase 目录结构:
用于运行的命令:
docker-compose build
docker-compose up
【问题讨论】:
-
我们可以看到错误吗?我只看到了配置(感谢详细的文档),但没有看到错误。
标签: postgresql spring-boot docker liquibase