# Docker

Using a docker container has numerous advantages, including:

  • Effortless deployments on Heroku, Amazon ECS, or Google Cloud Engine
  • Highly secure yet highly scalable to meet any hosting requirements
  • Portability which allows for moving hosting environments efficiently

# Step 1: Add a Dockerfile to your project

First step is to create a Dockerfile in your project.

The following sample Dockerfile will build the Retype project and create a httpd image based container as the output.

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder
WORKDIR /build
COPY . /build
RUN dotnet tool install retypeapp --tool-path /bin
RUN retype build --output .docker-build/

FROM httpd:latest
COPY --from=builder /build/.docker-build/ /usr/local/apache2/htdocs/

# Step 2: Build the image

After creating the Dockerfile you can use your local Docker instance to build the image with the following command:

docker build -t myorg/myapplication:latest .

To confirm that the build worked, run the container locally with:

docker run --rm -p 8080:80 myorg/myapplication:latest

You should be able to now open a web browser and browse to your IP address on port 8080. If running locally, localhost:8080 should work.

# Step 3: Publish the Image

After building your docker container, you can publish the container to any free-to-use repository such as Docker Hub. See the Docker Hub docs for more details.