RUN dotnet publish -c Release -o out
Command builds sln file directly and it causes wrong files to publish. Instead of this, you should build your csproj file directly.
WORKDIR /PATH/TO/YOUR/CSPROJ/FILE
RUN dotnet publish api.csproj -c Release -o out