For hosting and running we are using Nginx Alpine. Here is the Dockerfile
We are not using nginx directly for serving the index.html page, instead we are using a shell script -
docker-entrypoint.sh. Here is the implementation of
window.API_ENDPOINT from the
$API_ENDPOINT environment variable using the
cat command. Then we are starting the
nginx web server with daemon mode off. And in the Dockerfile we are using this shell script as entry point - so that the env.js file will be populated and we will be running the nginx web server.
Here is the
Please note we are including the
env.js file - which will set the API endpoint variable.
And here is the
And when can build the image using the following command -
docker build -t anuraj/staticweb:v1 . - this command will build the image and we can run the container using following command -
docker run -p 8080:80 -e API_ENDPOINT="https://api.example.com" anuraj/staticweb:v1 - Please note we are passing the
API_ENDPOINT as an environment variable. We can browse the application in http://localhost:8080. Here is the screenshot of the application running.