-
Notifications
You must be signed in to change notification settings - Fork 14
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.
- Run the Reference Architecture API as a docker service, with all dependencies hosted inside Docker containers.
- Run the Reference Architecture API as a single docker image, with dependencies running on the local machine or other hosted environments.
Running the Reference Architecture as a Docker Service requires Docker Compose and the ./docker-compose.yml configuration file.
The ./docker-compose.yml configuration file defines one network
- dbnet
and two services
- notetaking
- mongodb
The notetaking service is configured to be available on port 5002 and be dependent on the availability of the mongodb service. The mongodb service makes itself available on on port 27017, for administrative purposes. Each of the two services is configured to use the same network, dbnet. (NOTE: The MongoDb port would likely not be publicly exposed in a production scenario.) The notetaking service and the mongodb service are both configured to communicate with one another via the dbnet network.
Issue the following command, from the repository root, to run the service.
docker-compose upThis should produce output similar to the following:

The command builds the following docker images and then runs them as a service.

When the command has completed, you can confirm that the service is running by issuing the following command:
curl http://{{docker-machine-ip}}:5002/pingPrior 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.
The following command can be used to run the docker container. This command assumes certain dependencies are in place and running in the local environment, such as a MongoDB server.
docker run -itd -p 5001:80 \
-e ASPNETCORE_ENVIRONMENT \
-e NoteTaker__NotificationService__SendGrid__ApiKey \
-e ConnectionStrings__NoteTakingService \
--name refarch_api walterpinson/reference-architecture-apiAlternatively, the ./sh/build_container.sh bash script can be run to achieve the same result.