|
| 1 | +To run your .NET Core project in Docker and make it accessible on port 5195, you need to create a Dockerfile for your application, build the Docker image, and run it while mapping the desired port. Here's how to do it step by step: |
| 2 | + |
| 3 | +1. Create a Dockerfile |
| 4 | +Create a Dockerfile in the root of your project: |
| 5 | + |
| 6 | +``` |
| 7 | +# Use the official .NET runtime image as the base image |
| 8 | +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base |
| 9 | +WORKDIR /app |
| 10 | +
|
| 11 | +# Copy the build output from your local machine |
| 12 | +COPY ./bin/Release/net8.0/publish ./ |
| 13 | +
|
| 14 | +# Expose port 5195 |
| 15 | +EXPOSE 5195 |
| 16 | +
|
| 17 | +# Define the entry point |
| 18 | +ENTRYPOINT ["dotnet", "BCMS_backend.dll"] |
| 19 | +``` |
| 20 | +2. Build the Project for Release |
| 21 | +Make sure to build your project in release mode and publish it: |
| 22 | + |
| 23 | +``` |
| 24 | +dotnet publish -c Release -o ./bin/Release/net8.0/publish |
| 25 | +``` |
| 26 | +3. Build the Docker Image |
| 27 | +Build a Docker image using the Dockerfile: |
| 28 | + |
| 29 | +``` |
| 30 | +docker build -t bcms-backend . |
| 31 | +``` |
| 32 | +4. Run the Docker Container |
| 33 | +Run the container while mapping port 5195 on the host to 5195 in the container: |
| 34 | + |
| 35 | +``` |
| 36 | +docker run -d -p 5195:5195 bcms-backend --urls=http://+:5195 |
| 37 | +``` |
| 38 | +Here’s what happens: |
| 39 | + |
| 40 | +-d: Runs the container in detached mode. |
| 41 | +-p 5195:5195: Maps port 5195 on your local machine to port 5195 in the container. |
| 42 | +--urls=http://+:5195: Configures the application to listen on all network interfaces within the container on port 5195. |
| 43 | +5. Verify the Running Container |
| 44 | +Check if the container is running: |
| 45 | + |
| 46 | +``` |
| 47 | +docker ps |
| 48 | +``` |
| 49 | +You should see your container running and exposing port 5195. |
| 50 | + |
| 51 | +6. Access Your Application |
| 52 | +Open a browser or use a tool like curl to access the application: |
| 53 | + |
| 54 | +``` |
| 55 | +http://localhost:5195 |
| 56 | +``` |
| 57 | +If everything is set up correctly, your .NET Core project will now be running inside Docker and accessible via the specified port. |
0 commit comments