Currently working on a containerized .NET 8 application with Docker, and using HTMX on the frontend to hit my API endpoints. Currently however I am getting 1 of 2 errors when trying to hit those endpoints locally on my running container. If I go to the local url http://[::]:8080/views/register/register.html and attempt to register, the only error I get is (blocked:other) in the status column in the chrome dev tools. When I hit the same endpoint but from http://localhost:8080/views/register/register.html (which I thought should be effectively the same url) the status column shows the error (failed)net::ERR_CONNECTION_RESET. I am assuming that this is an issue in one of my docker files / my docker compose file, but could use some assistance. It may also be worth noting that when I run just my .NET application locally, not through the container, I can hit my swagger page to test the endpoints, and can confirm they are working successfully, which is part of what leads me to believe it is something wrong in my docker configuration.
I have tried altering my docker compose file for which ports are exposed for my backend application
command: --init-file /server/data/Database.sql
- ./mysql-data:/var/lib/mysql
condition: service_healthy
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=craigsaudev
- MYSQL_PASSWORD=testpass
- ./server/init:/docker-entrypoint-initdb.d
test: ['CMD-SHELL', 'mysqladmin ping -h 127.0.0.1 --password="" --silent']
<code>services:
server:
build:
context: .
target: final
ports:
- '5286:80'
command: --init-file /server/data/Database.sql
volumes:
- ./mysql-data:/var/lib/mysql
depends_on:
db:
condition: service_healthy
develop:
watch:
- action: sync
path: ./server
target: /src/server
client:
build:
context: ./client
ports:
- '8080:80'
develop:
watch:
- action: sync
path: ./client
target: /src/client
db:
image: mysql:8
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=craigsaudev
- MYSQL_USER=testuser
- MYSQL_PASSWORD=testpass
ports:
- '3306:3306'
volumes:
- ./server/init:/docker-entrypoint-initdb.d
healthcheck:
test: ['CMD-SHELL', 'mysqladmin ping -h 127.0.0.1 --password="" --silent']
interval: 3s
retries: 5
start_period: 30s
</code>
services:
server:
build:
context: .
target: final
ports:
- '5286:80'
command: --init-file /server/data/Database.sql
volumes:
- ./mysql-data:/var/lib/mysql
depends_on:
db:
condition: service_healthy
develop:
watch:
- action: sync
path: ./server
target: /src/server
client:
build:
context: ./client
ports:
- '8080:80'
develop:
watch:
- action: sync
path: ./client
target: /src/client
db:
image: mysql:8
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=craigsaudev
- MYSQL_USER=testuser
- MYSQL_PASSWORD=testpass
ports:
- '3306:3306'
volumes:
- ./server/init:/docker-entrypoint-initdb.d
healthcheck:
test: ['CMD-SHELL', 'mysqladmin ping -h 127.0.0.1 --password="" --silent']
interval: 3s
retries: 5
start_period: 30s
Here for reference as well is my dockerfile for the .NET backend
<code># syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
################################################################################
# Learn about building .NET container images:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md
# Create a stage for building the application.
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
# This is the architecture you’re building for, which is passed in by the builder.
# Placing it here allows the previous steps to be cached across architectures.
# Leverage a cache mount to /root/.nuget/packages so that subsequent builds don't have to re-download packages.
# If TARGETARCH is "amd64", replace it with "x64" - "x64" is .NET's canonical name for this and "amd64" doesn't
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages
dotnet publish -a ${TARGETARCH/amd64/x64} --use-current-runtime --self-contained false -o /app
# If you need to enable globalization and time zones:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
################################################################################
# Create a new stage for running the application that contains the minimal
# runtime dependencies for the application. This often uses a different base
# image from the build stage where the necessary files are copied from the build
# The example below uses an aspnet alpine image as the foundation for running the app.
# It will also use whatever happens to be the most recent version of that tag when you
# build your Dockerfile. If reproducability is important, consider using a more specific
# version (e.g., aspnet:7.0.10-alpine-3.18),
# or SHA (e.g., mcr.microsoft.com/dotnet/aspnet@sha256:f3d99f54d504a21d38e4cc2f13ff47d67235efeeb85c109d3d1ff1808b38d034).
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS final
# Copy everything needed to run the app from the "build" stage.
COPY --from=build /app ./
# Switch to a non-privileged user (defined in the base image) that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
# and https://github.com/dotnet/dotnet-docker/discussions/4764
ENTRYPOINT ["dotnet", "server.dll"]
<code># syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
################################################################################
# Learn about building .NET container images:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md
# Create a stage for building the application.
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
COPY . /source
WORKDIR /source/server
# This is the architecture you’re building for, which is passed in by the builder.
# Placing it here allows the previous steps to be cached across architectures.
ARG TARGETARCH
# Build the application.
# Leverage a cache mount to /root/.nuget/packages so that subsequent builds don't have to re-download packages.
# If TARGETARCH is "amd64", replace it with "x64" - "x64" is .NET's canonical name for this and "amd64" doesn't
# work in .NET 6.0.
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages
dotnet publish -a ${TARGETARCH/amd64/x64} --use-current-runtime --self-contained false -o /app
# If you need to enable globalization and time zones:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
################################################################################
# Create a new stage for running the application that contains the minimal
# runtime dependencies for the application. This often uses a different base
# image from the build stage where the necessary files are copied from the build
# stage.
#
# The example below uses an aspnet alpine image as the foundation for running the app.
# It will also use whatever happens to be the most recent version of that tag when you
# build your Dockerfile. If reproducability is important, consider using a more specific
# version (e.g., aspnet:7.0.10-alpine-3.18),
# or SHA (e.g., mcr.microsoft.com/dotnet/aspnet@sha256:f3d99f54d504a21d38e4cc2f13ff47d67235efeeb85c109d3d1ff1808b38d034).
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS final
WORKDIR /app
# Copy everything needed to run the app from the "build" stage.
COPY --from=build /app ./
# Switch to a non-privileged user (defined in the base image) that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
# and https://github.com/dotnet/dotnet-docker/discussions/4764
USER $APP_UID
ENTRYPOINT ["dotnet", "server.dll"]
</code>
# syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
################################################################################
# Learn about building .NET container images:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md
# Create a stage for building the application.
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
COPY . /source
WORKDIR /source/server
# This is the architecture you’re building for, which is passed in by the builder.
# Placing it here allows the previous steps to be cached across architectures.
ARG TARGETARCH
# Build the application.
# Leverage a cache mount to /root/.nuget/packages so that subsequent builds don't have to re-download packages.
# If TARGETARCH is "amd64", replace it with "x64" - "x64" is .NET's canonical name for this and "amd64" doesn't
# work in .NET 6.0.
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages
dotnet publish -a ${TARGETARCH/amd64/x64} --use-current-runtime --self-contained false -o /app
# If you need to enable globalization and time zones:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
################################################################################
# Create a new stage for running the application that contains the minimal
# runtime dependencies for the application. This often uses a different base
# image from the build stage where the necessary files are copied from the build
# stage.
#
# The example below uses an aspnet alpine image as the foundation for running the app.
# It will also use whatever happens to be the most recent version of that tag when you
# build your Dockerfile. If reproducability is important, consider using a more specific
# version (e.g., aspnet:7.0.10-alpine-3.18),
# or SHA (e.g., mcr.microsoft.com/dotnet/aspnet@sha256:f3d99f54d504a21d38e4cc2f13ff47d67235efeeb85c109d3d1ff1808b38d034).
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS final
WORKDIR /app
# Copy everything needed to run the app from the "build" stage.
COPY --from=build /app ./
# Switch to a non-privileged user (defined in the base image) that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
# and https://github.com/dotnet/dotnet-docker/discussions/4764
USER $APP_UID
ENTRYPOINT ["dotnet", "server.dll"]
I have tried changing the port from 5286:80 to 5286:5286, as well as deleting my containers completely and rebuilding them. I have also attempted trying to hit my swagger page directly, which also seems like it is unable to be accessed. The expected output is that I would get some response from my server, whether successful if the request created a new user, or some validation error from my backend, but it doesn’t appear that the request ever even gets that far.