-
-
Notifications
You must be signed in to change notification settings - Fork 51
Docker
The Food Oasis application is deployed to production environments using Docker. Most developers will not need to concern themselves with docker, but if you are responsible for deployment or are just curious, this article explains how to run the application as a docker container on your development machine.
Pre-Requisite: You must have Docker installed on your machine. This is relatively strightforward for IOS, Linux and Windows 10 Pro users, but significantly more challenging for Window Home users.
You may build and run a fullstack docker container to your local docker engine on your development machine. This allows you to test the application in an environment that most closely mimcs the deployment environment prior to committing code to the GitHub repo and deploying to a live production environment. In particular, you can resolve issues with client-server interaction, routing, etc., and be sure that you are exercising the exact npm modules that will run in the deployment environment.
To build a fullstack container:
docker build -t fola .
This will use the contents of Dockerfile to build a docker image that includes both the web api express server, as well as the compiled static pages that comprise the react client code.
You can see that the image has been built by running
docker image ls
There should be an image named fola
.
You can run this this container using the environment variables from the server/.env file. First make sure the correct database connection information is uncommented in the server/.env file. If you are using the connection information for a remote database (not localhost), the command to run is:
docker run -p 5002:5001 --env-file server/.env fola
If you want to use a Postgres database on your own machine as described in Local Database, the docker container running the web app requires you to overwrite the POSTGRES_HOST setting with a special syntax that allows the container to reference the localhost server:
docker run -p 5002:5001 \
--env-file server/.env -e "POSTGRES_HOST=host.docker.internal" fola
When the container is run with either of the above commands, the terminal will show
any output from the server in the terminal window, and the docker container will stop if you close the terminal or stop it by typing Ctrl-C. You may alternatively
run the container in a detached mode by adding the -d
option after run
. Then the application will run silently in the detached mode, and you will need to manipulate it with standard docker commands to stop, remove, start or view logs
from the container.
You can now enter http://localhost:5002 in your browser to exercise the docker-hosted application (The port mapping -p 5002:5001 maps the container port 5001 to the localhost port 5002, to allow you to run your dev environment on port 5001).