Pages

Tuesday, March 27, 2018

Building daycare website [Part 8]: Running the production image locally using Docker

On my previous post I went over the Dockerfile to create the production image for the application. Before publishing it, let's test it locally using Docker for Windows. First, to create the image run:

docker build ./ -t daycare-app

Docker automatically uses the 'Dockerfile' on the current directly to build the image and then it tags it with 'daycare-app'. You will see a lot of output with all the intermediary steps, but at the end you will have an image tagged 'daycare-app:latest' in your local image registry. Now, to run a container locally with this image:

docker run --rm -it -p 5000:5000 daycare-app

Dissecting each of the parameters:

  • --rm: Automatically remove the container and clean up its file system when it exits.
  • -it: Mark the process as interactive, which creates a shell for the container and allows you to see the output of the process on the terminal.
  • -p: Maps the port 5000 of the host to the port 5000 of the container. Why 5000? Because if you remember in the Docker file the process starts with "CMD ASPNETCORE_URLS=http://*:$PORT dotnet Daycare.dll", which allows the consumer to provide the port with an environment variable. Note also that the Dockerfile defines a default value for the  PORT variable: "ENV PORT=5000".

Once the container starts you can browse to http://localhost:5000 to load the application. Next up, deploy the image and host it on Heroku.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.