Skip to content

containerization

Walter Pinson edited this page Dec 18, 2017 · 12 revisions

Containerization

The Reference Architecture API uses Docker for containerization and to support a build once run in all environments scenario.

The repository includes three (3) Docker configuration files that, collectively, support various build and deploy scenarios.

File Name Description
./.dockerignore Instructs Docker to ignore files and folders when building images
./Dockerfile Instructions to build docker image
./docker-compose.yml Instructions to build a docker service

There are two approaches to running the Reference Architecture API.

  1. Run the Reference Architecture API as a docker service, with all dependencies hosted inside Docker containers.
  2. Run the Reference Architecture API as a single docker image, with dependencies running on the local machine or other hosted environments.

Run the Reference Architecture API as a Docker Service

Run the Reference Architecture API as Single Docker Image

Build and Run the Reference Architecture API Service

Build the API Image

Prior to running a docker container, we must first build a docker image.

This is a simple build. The Dockerfile assumes that the application has already been built and published into the ./publish folder.

FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY ./publish .
ENTRYPOINT ["dotnet", "Infrastructure.WebApi.dll"]

The following command builds the image.

docker build -t walterpinson/reference-architecture-api .

Alternatively, the ./sh/build_image.sh script can be run to achieve the same result.

Build and Run the API Container

The following command can be used to build and run the docker container. This command assumes certain dependencies are in place and running in the local environment, such as MongoDB.

docker run  -itd -p 5001:80 \
-e ASPNETCORE_ENVIRONMENT \
-e NoteTaker__NotificationService__SendGrid__ApiKey \
-e ConnectionStrings__NoteTakingService \
--name refarch_api walterpinson/reference-architecture-api

Alternatively, the ./sh/build_container.sh bash script can be run to achieve the same result.

Clone this wiki locally