Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker runs in VS but got error when publishing to AWS? error CS5001: Program does not contain a static 'Main' method suitable for an entry point

I installed AWS toolkit for Visual Studio 2017 (V15.7.3) and created a new empty Asp.Net core 2.1 project with API template and Linux docker support. I can run it in Visual Studio.

Visual Studio Docker output after loaded the project

========== Preparing Containers ==========
Getting Docker containers ready...
docker-compose  -f "C:\work\Strats\docker-compose.yml" -f "C:\work\Strats\docker-compose.override.yml" -f "C:\work\Strats\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose607729401690719332 --no-ansi config
The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.
services:
  processfiles:
    build:
      context: C:\work\Strats
      dockerfile: ProcessFiles/Dockerfile
      target: base
    entrypoint: tail -f /dev/null
    environment:
      ASPNETCORE_ENVIRONMENT: Development
      ASPNETCORE_HTTPS_PORT: '44347'
      ASPNETCORE_URLS: https://+:443;http://+:80
      DOTNET_USE_POLLING_FILE_WATCHER: '1'
      NUGET_FALLBACK_PACKAGES: /root/.nuget/fallbackpackages
    image: processfiles:dev
    labels:
      com.microsoft.visualstudio.debuggee.arguments: ' --additionalProbingPath /root/.nuget/packages
        --additionalProbingPath /root/.nuget/fallbackpackages  bin/Debug/netcoreapp2.1/ProcessFiles.dll'
      com.microsoft.visualstudio.debuggee.killprogram: /bin/bash -c "if PID=$$(pidof
        -x dotnet); then kill $$PID; fi"
      com.microsoft.visualstudio.debuggee.program: dotnet
      com.microsoft.visualstudio.debuggee.workingdirectory: /app
    ports:
    - published: 49971
      target: 80
    - published: 44347
      target: 443
    volumes:
    - C:\work\Strats\ProcessFiles:/app:rw
    - C:\Users\...\vsdbg\vs2017u5:/remote_debugger:ro
    - C:\Users\...\AppData\Roaming\ASP.NET\Https:/root/.aspnet/https:ro
    - C:\Users\...\AppData\Roaming\Microsoft\UserSecrets:/root/.microsoft/usersecrets:ro
    - C:\Program Files\dotnet\sdk\NuGetFallbackFolder:/root/.nuget/fallbackpackages:ro
    - C:\Users\...\.nuget\packages:/root/.nuget/packages:ro
version: '3.4'
docker ps --filter "status=running" --filter "name=dockercompose607729401690719332_processfiles_" --format {{.ID}} -n 1
docker-compose  -f "C:\work\Strats\docker-compose.yml" -f "C:\work\Strats\docker-compose.override.yml" -f "C:\work\Strats\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose607729401690719332 --no-ansi build 
The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.
Building processfiles
Step 1/4 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
 ---> 04aae08f15c5
Step 2/4 : WORKDIR /app
 ---> Using cache
 ---> 135955e04284
Step 3/4 : EXPOSE 49971
 ---> Using cache
 ---> 2e1bb95e0d70
Step 4/4 : EXPOSE 44347
 ---> Using cache
 ---> 89dc3708552d
Successfully built 89dc3708552d
Successfully tagged processfiles:dev
docker-compose  -f "C:\work\Strats\docker-compose.yml" -f "C:\work\Strats\docker-compose.override.yml" -f "C:\work\Strats\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose607729401690719332 --no-ansi up -d --no-build --force-recreate --remove-orphans
The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.
Creating network "dockercompose607729401690719332_default" with the default driver
Creating dockercompose607729401690719332_processfiles_1 ... 
Creating dockercompose607729401690719332_processfiles_1 ... done
Done!  Docker containers are ready.

Docker output when running in Visual Studio

========== Debugging ==========
docker ps --filter "status=running" --filter "name=dockercompose607729401690719332_processfiles_" --format {{.ID}} -n 1
1cad14cb758c
Launching https://localhost:44347/api/values ...

Visual studio Build output

1>------ Build started: Project: docker-compose, Configuration: Debug Any CPU ------
1>docker ps --filter "status=running" --filter "name=dockercompose607729401690719332_processfiles_" --format {{.ID}} -n 1
1>1cad14cb758c
1>docker exec -i 1cad14cb758c /bin/bash -c "if PID=$(pidof -x dotnet); then kill $PID; fi"
1>C:\work\Strats\ProcessFiles\ProcessFiles.csproj : warning NU1701: Package 'System.Linq.Queryable 4.0.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project.
1>ProcessFiles -> C:\work\Strats\ProcessFiles\bin\Debug\netcoreapp2.1\ProcessFiles.dll
1>Done building project "ProcessFiles.csproj".
1>docker-compose  -f "C:\work\Strats\docker-compose.yml" -f "C:\work\Strats\docker-compose.override.yml" -f "C:\work\Strats\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose607729401690719332 --no-ansi up -d
1>The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.
1>dockercompose607729401690719332_processfiles_1 is up-to-date
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

So it runs and shows the default value api sample in browser.

Now I right click the project and click "Publish container to AWS..." after a fix on the Dockerfile (Docker for Windows building added prefix `/var/lib/docker/tmp/` for COPY?). However, it failed with the following messages in AWS message box?

Inspecting Dockerfile to figure how to build project and docker image
... Skip building project since it is done as part of Dockerfile
Executing docker build
... invoking 'docker build', working folder 'C:\work\Strats\ProcessFiles, docker file C:\work\Strats\ProcessFiles\Dockerfile, image name processfiles:latest'
... docker build: Sending build context to Docker daemon  1.176MB
... docker build: Step 1/17 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
... docker build:  ---> 04aae08f15c5
... docker build: Step 2/17 : WORKDIR /app
... docker build:  ---> Using cache
... docker build:  ---> 135955e04284
... docker build: Step 3/17 : EXPOSE 49971
... docker build:  ---> Using cache
... docker build:  ---> 2e1bb95e0d70
... docker build: Step 4/17 : EXPOSE 44347
... docker build:  ---> Using cache
... docker build:  ---> 89dc3708552d
... docker build: Step 5/17 : FROM microsoft/dotnet:2.1-sdk AS build
... docker build:  ---> 7c3e298d40ac
... docker build: Step 6/17 : WORKDIR /src
... docker build:  ---> Using cache
... docker build:  ---> 6b6446592420
... docker build: Step 7/17 : COPY ProcessFiles.csproj ProcessFiles/
... docker build:  ---> 024a84501cff
... docker build: Step 8/17 : RUN dotnet restore ProcessFiles/ProcessFiles.csproj
... docker build:  ---> Running in 1ef41c99d3bc
... docker build:   Restoring packages for /src/ProcessFiles/ProcessFiles.csproj...
... docker build:   Generating MSBuild file /src/ProcessFiles/obj/ProcessFiles.csproj.nuget.g.props.
... docker build:   Generating MSBuild file /src/ProcessFiles/obj/ProcessFiles.csproj.nuget.g.targets.
... docker build:   Restore completed in 770.82 ms for /src/ProcessFiles/ProcessFiles.csproj.
... docker build: Removing intermediate container 1ef41c99d3bc
... docker build:  ---> 276efaf02bd4
... docker build: Step 9/17 : COPY . .
... docker build:  ---> 128814476275
... docker build: Step 10/17 : WORKDIR /src/ProcessFiles
... docker build: Removing intermediate container 004eb873b480
... docker build:  ---> 8c1741062d87
... docker build: Step 11/17 : RUN dotnet build ProcessFiles.csproj -c Release -o /app
... docker build:  ---> Running in fd25517b7941
... docker build: Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
... docker build: Copyright (C) Microsoft Corporation. All rights reserved.
... docker build:   Restore completed in 55.9 ms for /src/ProcessFiles/ProcessFiles.csproj.
... docker build: CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/ProcessFiles/ProcessFiles.csproj]
... docker build: Build FAILED.
... docker build: CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/ProcessFiles/ProcessFiles.csproj]
... docker build:     0 Warning(s)
... docker build:     1 Error(s)
... docker build: Time Elapsed 00:00:02.56
... docker build: The command '/bin/sh -c dotnet build ProcessFiles.csproj -c Release -o /app' returned a non-zero code: 1
Error executing "docker build"
Attempting to clean up any ELB resources created for the failed deployment
Unknown error publishing container to AWS

Here is the main method created by VS.

namespace ProcessFiles
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }
}

Dockerfile

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 49971
EXPOSE 44347

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ProcessFiles.csproj ProcessFiles/
RUN dotnet restore ProcessFiles/ProcessFiles.csproj
COPY . .
WORKDIR /src/ProcessFiles
RUN dotnet build ProcessFiles.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish ProcessFiles.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ProcessFiles.dll"]
like image 281
ca9163d9 Avatar asked Jun 14 '18 18:06

ca9163d9


People also ask

What is ENV file in Docker?

env or by providing a path to your environment variables file using the --env-file command line option. Your configuration options can contain environment variables. Compose uses the variable values from the shell environment in which docker-compose is run.

What does copy mean in Dockerfile?

COPY is a docker file command that copies files from a local source location to a destination in the Docker container. ADD command is used to copy files/directories into a Docker image. Syntax: COPY <src> <dest> Syntax: ADD source destination.


1 Answers

The pathing in your build phase is wonky. Your project file is being copied to the subfolder /src/ProcessFiles, but the source files are being copied to /src. Setting the WORKDIR before copying should allow them to land in the right place.

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ProcessFiles.csproj ProcessFiles/
RUN dotnet restore ProcessFiles/ProcessFiles.csproj
WORKDIR /src/ProcessFiles
COPY . .
RUN dotnet build ProcessFiles.csproj -c Release -o /app
like image 151
superstator Avatar answered Oct 04 '22 04:10

superstator