In this article, We are going to dockerize the microservices and apigateway. In last post we have learned about creating microservices and apigateway.
Now, Lets start with apigateway. First create a Dockerfile and .dockerignore file in an apigateway.
Now run a command in a terminal.
docker build -t dev-apigateway -f Dockerfile .
It will create an image file named dev-apigateway.
Now follow the same step and create a Dockerfiles and .dockeignore files for products and orders microservices.
Products dockerfile should look like this
FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:80
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
WORKDIR /src
COPY ["Products.csproj", "./"]
RUN dotnet restore "Products.csproj"
COPY . .
RUN dotnet build "Products.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Products.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Products.dll"]
After creating dockerfile run docker build command.
docker build -t dev-orders -f Dockerfile .
Orders dockerfile should look like this
FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:80
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
WORKDIR /src
COPY ["Orders.csproj", "./"]
RUN dotnet restore "Orders.csproj"
COPY . .
RUN dotnet build "Orders.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Orders.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Orders.dll"]
After creating dockerfile run docker build command.
docker build -t dev-orders -f Dockerfile .
Now we have a 3 images in docker desktop. We will push those images in docker hub. First create an account on a docker hub. Open a terminal and type docker login. It will ask you to type username and password. Once your login Succeeded then run following commands to push images to docker hub.
docker tag dev-apigateway siddharthborge99/dev-apigateway
docker push siddharthborge99/dev-apigateway
In a same way push orders and products images in docker hub. After pushing all images in docker hub. It should look like this.
As you can see in above picture that we have all three images is available. We are going to use those images in deployment on kubernetes.
Top comments (0)