docker init
is a CLI tool that helps you create a Dockerfile
for your app. It detects the platform and the main project of your app and generates a Dockerfile
for you. The downside of this approach is that you need to manually add referencing projects to the Dockerfile
if your app has project references.
# Bazh/Zsh
REPOSITORY_ROOT=$(git rev-parse --show-toplevel)
# PowerShell
$REPOSITORY_ROOT = git rev-parse --show-toplevel
-
Move to the
monolith
directory.cd $REPOSITORY_ROOT/monolith
-
Run
docker init
to create a newDockerfile
for the app.docker init
Follow the prompts to create a
Dockerfile
for the app.- Choose
ASP.NET Core
as the application platform - Choose
eShopLite.Store
as the main project - Enter
9.0
as the .NET SDK version - Enter
8080
as the host port number
- Choose
-
Open the
Dockerfile
and add theRUN
instruction below:# Find this line COPY --from=build /app . # Add the following RUN instruction RUN chown $APP_UID /app
# Find this line USER $APP_UID # Add the following RUN instruction RUN touch /app/Database.db
-
Build the container image.
# To follow the build platform docker build -t eshoplite-store:latest . # To specify the target platform docker build --platform=linux/amd64 --build-arg TARGETARCH=amd64 -t eshoplite-store:latest .
-
Run a container from the container image.
docker run -d -p 8080:8080 --name store eshoplite-store:latest
-
Open the browser and navigate to
http://localhost:8080
to see the web app running. -
Stop and remove the container.
docker stop store docker rm store --force
-
Delete the container image.
docker rmi eshoplite-store:latest --force