Search code examples
dockersqliteumbraco

Sqlite running inside a docker container


I have a umbraco 10 web app running inside a docker container. I would like to attach the SQLite storage that I use to the container. The file is located at ~/umbraco/Data/Umbraco.sqlite.db.

This is the docker file for building the image

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 4000
ENV ASPNETCORE_URLS http://+:4000

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["moranmono.web/moranmono.web.csproj", "moranmono.web/"]
RUN dotnet restore "moranmono.web/moranmono.web.csproj"
COPY . .
WORKDIR "/src/moranmono.web"
RUN dotnet build "moranmono.web.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "moranmono.web.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "moranmono.web.dll"]

This is the docker-compose file

version: '3.9'

services:
  moranmono-umbraco:
    container_name: moranmono-umbraco
    build:
      context: .
      dockerfile: moranmono.web/Dockerfile
    ports:
      - 4000:4000
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    volumes:
      - ~/.vsdbg:/remote_debugger:rw

I tried running the docker container but it doesn't recognize the SQLite DB file and I am not sure where I am supposed to add the SQLite support, in the docker file or on the docker-compose file

I get the following error after running the container

Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 14: 'unable to open database file'.
2022-12-13T14:56:26.108469888Z    at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
2022-12-13T14:56:26.108472054Z    at Microsoft.Data.Sqlite.SqliteConnectionInternal..ctor(SqliteConnectionStringBuilder connectionOptions, SqliteConnectionPool pool)
2022-12-13T14:56:26.108474638Z    at Microsoft.Data.Sqlite.SqliteConnectionPool.GetConnection()
2022-12-13T14:56:26.108477304Z    at Microsoft.Data.Sqlite.SqliteConnectionFactory.GetConnection(SqliteConnection outerConnection)
2022-12-13T14:56:26.108479346Z    at Microsoft.Data.Sqlite.SqliteConnection.Open()
2022-12-13T14:56:26.108481096Z    at Umbraco.Extensions.DbConnectionExtensions.IsAvailable(IDbConnection connection)

Solution

  • You have to mount the sqlite file inside the docker image using volumes. Something like this will do the trick-

    volumes:
    - ./path/to/sqlite-folder:/app/db