Adding .Net Application with React in the frontend and SQLite to Docker

  .net, .net-5, docker, reactjs, sqlite

I have built an small CRUD application using .Net 5 with React in the front end and SQLite for the database.

The app is working fine locally and all connections are correct both to the API and to the database.

I have been trying to put the whole application in a docker container. This also works fine but when I try to run the application in docker, I get an error saying that the SQLite table doesn’t exists.

I have done some reading and I think docker doesn’t see the migrations done on the application.

Is there a way to fix this (if that’s what the issue is)?

This is my docker file below. The SQLite file is in the root of the .Net application and the React code in inside the ClientApp folder.

# Build stage
FROM mcr.microsoft.com/dotnet/sdk:5.0 as build

# Install NodeJS and NPM
RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl git nano
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - && apt-get install -yq 
nodejs build-essential

# Copy the files from the file system so they can built
COPY ./ /src
WORKDIR /src

# Install node
RUN npm install -g npm
RUN npm --version

# Opt out of .NET Core's telemetry collection
ENV DOTNET_CLI_TELEMETRY_OPTOUT 1

# Set node to production
ENV NODE_ENV production

# Run the publish command, which also runs the required NPM commands to build the     
# React front-end
RUN dotnet publish -c Release

# Run stage
FROM mcr.microsoft.com/dotnet/aspnet:5.0 as run

COPY --from=build /src/bin/Release/net5.0/publish /app
WORKDIR /app

ENTRYPOINT ["dotnet", "Restaurant-Picker.dll"]

Below you can see the first part of the error when I try to log in to the application that says that the table doesn’t exist. As mentioned above, the application works fine locally which means it’s seeing the database. Why doesn’t it see it in the container?

Docker container error

Source: Docker Questions

LEAVE A COMMENT