0

When I build my app without using docker-compose :

docker build -t aspnetapp .
docker run -d -p 8080:80 --name myapp aspnetapp

the docker container runs just fine. But when I try to run it, using docker-compose up, the image builds successfully but the website gives me errors on loading.

dockerfile:

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

RUN curl -sL https://deb.nodesource.com/setup_10.x |  bash -
RUN apt-get install -y nodejs

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "app.dll"]

docker-compose:

version: '3.4'

  services:
    app:
      image: aspnetapp     
      build: ./app
      ports:
        - "8080:80"
AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this:.

[1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Make sure the executable is in one of those directories, or update your PATH.
11
  • 4
    Where is your app trying to use npm if it's a dotnet application? Commented Oct 4, 2018 at 13:39
  • it's a dotnet-react app Commented Oct 4, 2018 at 13:40
  • Okay, well those react resources should be built and copied from the 'build-env"... I'm not sure if compose is really the problem here because if you had first built the container outside compose, then the entire image should be cached, and you would see no difference in behavior Commented Oct 4, 2018 at 13:42
  • but why does it not work when I use docker-compose? Everything works fine by doing docker build. I already specified in the dockerfile that it needs nodejs Commented Oct 4, 2018 at 13:43
  • You only said that the build environment has nodejs, not the runtime that apparently needs npm to do something Commented Oct 4, 2018 at 13:45

2 Answers 2

2

removing

environment: - ASPNETCORE_ENVIRONMENT=Development 

from the compose.override file fixed all this. I'm not sure why it's the problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Where was that in the code you posted in the quesiton?
1

Is your Dockerfile in ./ or ./app? If it's in ./ change docker-compose.yml to build: ./

EDIT

I've just realised that you are specifying both image and build in your docker-compose.yml; get rid of the image.

1 Comment

./app. I said the docker-compose builds fine. Its just when I run it that I get errors

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.