skip to Main Content

I am stuck for days with creating a dockerimage of my asp.net core web api project.

Everything works in VisualStudio but I want to create/build the image to use it on different linux docker host.

I can see it maps some local windows folders and assign some folders also to the project path.
We don’t have a Docker Hub or other Registry. So I thought I build the image and import it to our local linux host where docker is installed.

Should it not copy everything into the docker image?

How can this goal be achieved?

Thank you very much!

I have tried different dockerfiles. But I think I need some help to understand this process.

Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
#ENV ASPNETCORE_URLS=http://+:5000
USER app
WORKDIR /app
EXPOSE 5000

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
#ARG PASSWORD_ENV_SEEDED
WORKDIR /src
COPY ["src/API/API.csproj", "src/API/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Shared/Shared.csproj", "src/Shared/"]
COPY ["src/Client/Client.csproj", "src/Client/"]
COPY ["src/Client.Infrastructure/Client.Infrastructure.csproj", "src/Client.Infrastructure/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
RUN dotnet restore "./src/API/./API.csproj"
COPY . .
WORKDIR "/src/API"
RUN dotnet build "./API.csproj" -c Release -o /app/build
#generate the cert, define the path to store it and password to use
#RUN dotnet dev-certs https -ep /https/aspnetapp.pfx -p ${PASSWORD_ENV_SEEDED}

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./API.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
#COPY --chmod=0755 --from=build /https/* /https/
ENTRYPOINT ["dotnet", "ApplicationName.API.dll"]

Docker-Compose from VS

version: '3.4'

services:
  kemcalapp:
    image: ${DOCKER_REGISTRY-}app
    build:
      context: .
      dockerfile: srcAPIDockerfile
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "5000:5000"
    restart: on-failure
    container_name: APP

2

Answers


  1. Chosen as BEST ANSWER

    Thank you all. I could finally build the image with

    docker build -f .srcAPIDockerfile -t appname . 
    

    and then export it as .tar with

    docker save -o
    

    I will now build my bitbucket-pipeline from the repo and save the file manually.


  2. Docker images are usually not transported from server A to server B (like drag and drop or like some file be like), either you build them together with a Dockerfile or you pull them from a repo-server e.g. hub.docker.com.

    Since you have a Dockerfile, you can upload this Dockerfile and your source code (just your whole project folder) to your other Docker server (via ftp, ssh or similar) and then build the image with the following command docker build -t yourImageName .

    • docker build: This part of the command tells Docker to build a new image.
    • -t yourImageName: The "-t" flag is used to tag the image with a name. In this case, "yourImageName". You can replace "yourImageName" with whatever name you prefer.
    • .: The dot at the end of the command specifies the build context. It tells Docker to look for the Dockerfile in the current directory.

    Normally, you should now see bars in the console that work from left to right, pulling, building or extracting your/other images.

    Once the image has been built, it can be used normally as an example: docker run -d --name myContainerName yourImageName of course you can add other parameters like -p for port or -v for the volume mapping or how you did it in a docker compose file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search