Deployment: Docker - 100mslive/100ms-web GitHub Wiki
Docker
Table of Contents
There are two docker setups that come out of the box with the app. one for development and another for production. The development is handled by the Dockerfile.dev
file, and production is handled by Dockerfile
file. Docker Compose is also set up (through docker-compose.yml
file) to run the production container. This wiki assumes you have docker already installed.
Building for development
move to the root folder of the project where the Dockerfile.dev
and package.json
are located. Then just run
docker build -f Dockerfile.dev -t 100ms-web .
the -f
flag tells us to use the Dockerfile.dev
instead of the default Dockerfile
. This is mandatory and not using -f
will make docker build using the production docker file.
the -t
flag tags our image. Think of this simply as a human-readable name for the final image. Since we named the image '100ms-web', we can refer to that image when we run a container.
the .
after the name tells docker that the Dockerfile.dev
is located in the current directory.
once the build is done, just start the container with
docker run -dp 8080:8080 100ms-web
Note we use 8080:8080
here because we used the port 8080 and exposed the internal port of the container 8080, feel free to use any port that suits you. Also note that we used 100ms-web
after the port number which should be exactly the same name you used to tag the container with -t
in the previous section
That's it. Your app is ready. You can visit the app at http://locahost:8080
Building for production
For building for production is slightly more complex. So we use docker-compose
to set up our environment. The Dockerfile
is configured to install node, build the app, set environment variables, install nginx, set the configurations and deploy.
First let's build the container.
docker-compose -f docker-compose.yml build
this builds the container with the necessary environment. The configuration for nginx is taken from nginx.conf
in the root directory.
Once this is successful, run
docker run -p 80:80 --name 100ms 100ms-web-prod
this starts the container. Once its up, you should be able to use the website in http://localhost.
Customizing your production build
adding environment variables
The Dockerfile
adds the minimum required environment variables by default. In case you want to add more environment variables, add them to Dockerfile
in the following format
ENV MYENVVARIABLE=SOMEVAL
make sure this is below the other ENV
variables in the docker file.
customizing nginx configuration
If you are deploying this docker to some server, and want to add things like SSL certificate or add a domain etc, just update the nginx.conf
with the necessary details and then build the container again. You could also just rename your own existing configuration to nginx.conf
and place it in the root folder and then build docker. Docker will set your nginx with that configuration.