# Bazh/Zsh
REPOSITORY_ROOT=$(git rev-parse --show-toplevel)# PowerShell
$REPOSITORY_ROOT = git rev-parse --show-toplevelUnlike the other microservice apps in this repository, this eShopLite.ProductApi app has to use Dockerfile for containerization because it requires the RUN instruction to create an SQLite database file inside the container.
-
Make sure you have been running Docker Desktop. If not, start Docker Desktop.
-
Move to the
msadirectory.cd $REPOSITORY_ROOT/msa
-
Build the container image.
# To follow the build platform docker build -f Dockerfile.product -t eshoplite-product:latest . # To specify the target platform docker build --platform=linux/amd64 --build-arg TARGETARCH=amd64 -f Dockerfile.product -t eshoplite-product:latest .
-
Run a container from the container image.
docker run -d -p 5051:8080 --name product eshoplite-product:latest
-
Open the browser and navigate to
http://localhost:5051/api/productsto see the web app running. -
Stop and remove the container.
docker stop product docker rm product --force
-
Delete the container image.
docker rmi eshoplite-product:latest --force
Jib is a tool that builds a container image for your Java app without a Dockerfile. It's directly integrated into the Maven or Gradle build process. The downside of this approach is that you can't add the RUN instruction. If it's really necessary, use the Dockerfile or build a custom base image that has already applied the RUN instruction.
-
Make sure you have been running Docker Desktop. If not, start Docker Desktop.
-
Make sure you have logged in Docker daemon to your preferred container registry. If not, run the following command:
docker login
-
Move to the
msadirectory.cd $REPOSITORY_ROOT/msa
-
Set the variables for building container image. Replace
{{YOUR_CONTAINER_REGISTRY}}with your preferred container registry. For example,my_container_registry.azurecr.io. If you want to use Docker Hub, you can use your Docker Hub username.REGISTRY="{{YOUR_CONTAINER_REGISTRY}}"$REGISTRY = "{{YOUR_CONTAINER_REGISTRY}}"
-
Build the container image.
./src/eShopLite.WeatherApi/mvnw clean package \ -f ./src/eShopLite.WeatherApi/pom.xml \ -Dimage="$REGISTRY/eshoplite-weather:latest"./src/eShopLite.WeatherApi/mvnw clean package ` -f ./src/eShopLite.WeatherApi/pom.xml ` -Dimage="$REGISTRY/eshoplite-weather:latest"
-
Pull the container image from the container registry.
docker pull "$REGISTRY/eshoplite-weather:latest" docker tag "$REGISTRY/eshoplite-weather:latest" eshoplite-weather:latest
-
Run a container from the container image.
docker run -d -p 5050:5050 --name weather "eshoplite-weather:latest" -
Open the browser and navigate to
http://localhost:5050/api/weatherforecastto see the app running. -
Stop and remove the container.
docker stop weather docker rm weather --force
-
Delete the container image.
docker rmi eshoplite-weather:latest --force docker rmi "$REGISTRY/eshoplite-weather:latest" --force
MSBuild has a feature to build your .NET app containerized without a Dockerfile. The downside of this approach is that you can't add the RUN instruction. If it's really necessary, use the Dockerfile or build a custom base image that has already applied the RUN instruction.
-
Make sure you have been running Docker Desktop. If not, start Docker Desktop.
-
Move to the
msadirectory.cd $REPOSITORY_ROOT/msa
-
Run the following
dotnet publishcommand to build the app.dotnet publish ./src/eShopLite.WebApp \ -t:PublishContainer \ --os linux --arch x64dotnet publish ./src/eShopLite.WebApp ` -t:PublishContainer ` --os linux --arch x64
-
If you want to change the base image to Ubuntu Chiseled image, use the following command.
dotnet publish ./src/eShopLite.WebApp \ -t:PublishContainer \ --os linux --arch x64 \ -p:ContainerBaseImage=mcr.microsoft.com/dotnet/aspnet:9.0-noble-chiseled \ -p:ContainerRepository=eshoplite-webstore \ -p:ContainerImageTag=latestdotnet publish ./src/eShopLite.WebApp ` -t:PublishContainer ` --os linux --arch x64 ` -p:ContainerBaseImage=mcr.microsoft.com/dotnet/aspnet:9.0-noble-chiseled ` -p:ContainerRepository=eshoplite-webstore ` -p:ContainerImageTag=latest
-
Run a container from the container image.
docker run -d -p 5000:8080 --name webstore eshoplite-webstore:latest
-
Open the browser and navigate to
http://localhost:5000to see the app running. Make sure that both/weatherand/productspages are not properly working, which is expected. -
Stop and remove the container.
docker stop webstore docker rm webstore --force
-
Delete the container image.
docker rmi eshoplite-webstore:latest --force
-
Create a new bridge network.
docker network create eshoplite
-
Run containers from each container image with the network attached
docker run -d -p 5000:8080 --network eshoplite --network-alias webstore --name webstore eshoplite-webstore:latest docker run -d -p 5050:5050 --network eshoplite --network-alias weather --name weather eshoplite-weather:latest docker run -d -p 5051:8080 --network eshoplite --network-alias product --name product eshoplite-product:latest
-
Open the browser and navigate to
http://localhost:5000to see the app running. Make sure this time both/weatherand/productspages are properly showing contents. -
Delete containers and network
docker stop webstore docker rm webstore --force docker stop weather docker rm weather --force docker stop product docker rm product --force docker network rm eshoplite --force
-
Make sure you have been running Docker Desktop. If not, start Docker Desktop.
-
Move to the
msadirectory.cd $REPOSITORY_ROOT/msa
-
Run the following command to run all the containers.
docker compose up
-
Open the browser and navigate to
http://localhost:5000to see the app running. -
Stop and remove the containers.
docker compose down