Skip to content

Failling to deploy docker image with .Net app to Lightsail

0

I've been trying to deploy simple web API (.Net9) to Lightsail Container. Here is the code:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello world");
app.Run();

And Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
WORKDIR /app
ENV ASPNETCORE_URLS=http://+:80

FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /src/appTest
COPY appTest/. .
RUN dotnet restore "appTest.csproj"
RUN dotnet publish "appTest.csproj" -c Release -o /app/publish --no-restore

FROM base AS final
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "appTest.dll"]

Configuration

Deployment fails with the following log:

[30/lip/2025:07:33:50] [deployment:5] Creating your deployment
[30/lip/2025:07:34:08] [deployment:5] Started 1 new node
[30/lip/2025:07:35:08] [deployment:5] Started 1 new node
[30/lip/2025:07:36:12] [deployment:5] Started 1 new node
[30/lip/2025:07:36:32] [deployment:5] Canceled

Container works fine on my machine but for some reason deployment to Lightsail keeps failing.

asked 10 months ago110 views
2 Answers
0
Accepted Answer

The image was stored not in ECR but in GitHub repo. The problem was that the repo was private. Lightsail was failing to download the image.

answered 10 months ago
AWS
SUPPORT ENGINEER
reviewed 10 months ago
0

There are a few potential issues that could be causing your Lightsail container deployment to fail:

  1. Container Name Mismatch: The most common issue with Lightsail container deployments is a mismatch between the container name in your containers.json and public-endpoint.json files. Make sure the containerName in your public-endpoint.json matches exactly what you've defined in containers.json.

For example, if your containers.json has:

{
"myapp": {
"image": "...",
"ports": {
"80": "HTTP"
}
}
}

Then your public-endpoint.json should have:

{
"containerName": "myapp",
"containerPort": 80
}
  1. Architecture Issues: Since you're developing on a local machine, there might be architecture compatibility issues. If you're using an M1/M2 Mac, make sure you're building your Docker image with the correct platform flag: --platform linux/x86_64.

  2. Docker Desktop Settings: If you're using Docker Desktop, try disabling "Use containerd for pulling and storing images" in the Docker Desktop settings, as this has been known to cause issues with image uploads to AWS services.

  3. Dockerfile Considerations:

  • Your Dockerfile looks generally correct, but ensure you're using the right .NET version (you mention .NET 9 in your description but use .NET 8 in your Dockerfile)
  • Make sure your ASPNETCORE_URLS environment variable is correctly set to match the port you're exposing
  • Verify that your application is properly listening on the port specified in your Lightsail configuration
  1. Lightsail Configuration: Double-check your Lightsail container service configuration, including:
  • Ensure the port mappings are correct
  • Verify that the container has sufficient resources allocated
  • Check that the public endpoint is properly configured

Try deploying with these adjustments and check the Lightsail logs for more detailed error information if the issue persists.
Sources
InvalidInputException error for containerName when deploying to AWS lightsail using AWS-CLI in Mac M1 | AWS re:Post
Lightsail image failed commit - 400 Bad Request | AWS re:Post

answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.