0

I'm learning docker and I'm trying to publish blazor wasm app into docker container.

Here is my docker-compose.yml:

version: '3.7'

services:
  reverseproxy:
    build:
      context: .
      dockerfile: nginx/nginx.Dockerfile
    ports:
      - "44395:44395"
    networks:
      testnet

  test.ui:
    build:
      context: .
      dockerfile: Web/Dockerfile
    depends_on:
      - reverseproxy
    environment:
      - ASPNETCORE_URLS=http://*:5005
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "5005:5005"
    networks:
      - testnet

networks:
  testnet: {}

nginx docker file:

FROM nginx

COPY nginx/nginx.local.conf /etc/nginx/nginx.conf

Blazor wasm Docker file:

FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS publish
RUN apk add nodejs
RUN apk add npm
WORKDIR /src
COPY . .
WORKDIR "/src/Web"
RUN npm install
RUN dotnet publish "Web.csproj" -c Release -o /output

FROM nginx:alpine
WORKDIR /usr/share/nginx/html
COPY --from=publish /output/wwwroot .

Till this point files were not copied properly.

Update 1:

Blazor wasm Docker file:

FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build-env
RUN apk add nodejs
RUN apk add npm
WORKDIR /app
COPY . ./                                         <--- Change here
WORKDIR "/app/Web"
RUN npm install
RUN dotnet publish -c Release -o output

FROM nginx:alpine
WORKDIR /usr/share/nginx/html
COPY --from=build-env /app/Web/output/wwwroot/ .  <--- Change here

Now when I run this docker file separately, the contents inside the folder /app/Web/output/wwwroot/ is copied to /usr/share/nginx/html

Everything compiles and builds fine. But when I run from docker compose, I get the following error and the reverse-proxy still continues to run.

enter image description here

So I've decided to get into test.ui container and I see that No such file or directory

C:\Users\xxxx>docker exec -it 18aa171dae9d sh
/app/Web # cd ..
/app # cd ..
/ # cd usr
/usr # cd share
/usr/share # cd nginx
sh: cd: can't cd to nginx: No such file or directory
/usr/share #

When I comment reverseproxy in docker-compose.yml, I can see the files are copied properly. But with reverseproxy enabled in docker-compose.yml, the directory gets lost. I'm not sure what overrides contents of my test.ui container.

Here are the build logs:

8>#31 [testui:dev build-env 5/5] RUN dotnet publish -c Release -o output
8>#31 0.788 MSBuild version 17.5.0+6f08c67f3 for .NET
8>#31 2.253   Determining projects to restore...
8>#31 7.795   Restored /app/Shared/Shared.csproj (in 4.75 sec).
8>#31 14.82   Restored /app/Web/Web.csproj (in 11.8 sec).
8>#31 18.41   Shared -> /app/Shared/bin/Release/net7.0/Shared.dll
...
8>#31 35.82   Web -> /app/Web/bin/Release/net7.0/Web.dll
8>#31 35.82   Web (Blazor output) -> /app/Web/bin/Release/net7.0/wwwroot
8>#31 36.26   Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
8>#31 36.26   Optimizing assemblies for size. This process might take a while.
8>#31 97.61   Compressing Blazor WebAssembly publish artifacts. This may take a while...
8>#31 133.3   Web -> /app/Web/app/Web/output/
8>#31 DONE 133.5s
8>#18 [testui:dev] exporting to image
8>#18 exporting layers

From the build logs I can see that COPY operation is not happening. After publish it starts exporting image.

Please assist me on where I'm wrong.

fingers10
  • 6,675
  • 10
  • 49
  • 87
  • Which container are you looking at? Each container and each image has an isolated filesystem; with what you've shown, I'd expect this setup to be running two Nginx instances, where `reverseproxy` just has some custom configuration (maybe it `proxy_pass` to the other container) and `test.ui` has default configuration and some static files. – David Maze Mar 20 '23 at 10:38
  • Yeah I can add `upstream` inside my `nginx config` and add `proxy_pass` as suggested. But before that my directory from `test.ui` gets lost somehow. – fingers10 Mar 20 '23 at 19:07
  • This looks like a visual studio bug. This error happens only when we run from visual studio not from command line – fingers10 Mar 21 '23 at 18:59

0 Answers0