![关注抖音创业](https://img.kancloud.cn/c5/ce/c5ced2ea291122851697114ca415ff95_1125x1680.png) [TOC] # 案例 > docker中使用sqllite数据库,数据库以目录方式挂载 ## Dockerfile Copy文件形式 ``` #拉取镜像 FROM openjdk:8 #调整时区 #上海时区 ENV TZ=PRC RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # sqllite RUN sudo apt-get -y update RUN sudo apt-get -y upgrade RUN sudo apt-get install -y sqlite3 libsqlite3-dev #获取jar包 ARG JAR_FILE=target/*.jar #目录不存在会自动创建 cd //opt/land-monito WORKDIR /opt/land-monitor #复制jar包 COPY ${JAR_FILE} land-monitor.jar COPY src/main/resources/db/monitor.db /opt/land-monitor/monitor.db RUN chmod 644 /opt/land-monitor/monitor.db #监听5001端口 EXPOSE 5001 #运行jar包 #java -jar /opt/app/app.jar -Xms256m -Xmx256m CMD ["-Xms256m","-Xmx256m"] ENTRYPOINT ["java","-Dfile.encoding=utf-8","-jar","land-monitor.jar"] ``` ## Dockerfile VOLUME形式 ``` VOLUME /opt/land-monitor ## VOLUME 指定容器中挂载点 ``` ### 启动 ``` docker run -p 5001:5001 --name land-monitor -v /root/sqllite/monitor.db:/opt/land-monitor land-monitor:1.0 ``` # yml配置文件database配置 ``` spring: datasource: url: jdbc:sqlite:/opt/land-monitor/monitor.db username: password: driver-class-name: org.sqlite.JDBC ```