Cloud Native Programming With Golang: Develop Microservice-Based High Performance Web Apps for the Cloud With Go by Martin Helmich & Mina Andrawos
Author:Martin Helmich & Mina Andrawos [Helmich, Martin && Andrawos, Mina]
Language: eng
Format: epub
Tags: Computers, Programming Languages, General, Programming, Open Source, Cloud Computing, Networking
ISBN: 9781787127968
Google: NvNFDwAAQBAJ
Publisher: Packt Publishing Ltd
Published: 2017-12-28T05:00:00+00:00
docker image ls output
Building containers for the frontend
Now that we have container images for our backend applications, we can direct our attention to the frontend application. Since this application runs in the user's browser, we do not really need a containerized runtime environment for it. What we do need though is a way to deliver the application to the user. Since the entire application consists of a bit of HTML and JavaScript files, we can build a container image that contains a simple NGINX web server that serves these files to the users.
For this, we will be building on the nginx:1.11-alpine image. This image contains a minimal version of the NGINX web server, built on Alpine Linux. Alpine is a Linux distribution optimized for small size. The entire nginx:1.11-alpine image is only 50 MB in size.
Add the following Dockerfile to your frontend application directory:
FROM nginx:1.11-alpine COPY index.html /usr/share/nginx/html/ COPY dist /usr/share/nginx/html/dist/ COPY node_modules/bootstrap/dist/css/bootstrap.min.css /usr/share/nginx/html/node_modules/bootstrap/dist/css/bootstrap.min.css COPY node_modules/react/umd/react.production.min.js /usr/share/nginx/html/node_modules/react/umd/react.production.min.js
COPY node_modules/react-dom/umd/react-dom.production.min.js /usr/share/nginx/html/node_modules/react-dom/umd/react-dom.production.min.js COPY node_modules/promise-polyfill/promise.min.js /usr/share/nginx/html/node_modules/promise-polyfill/promise.min.js COPY node_modules/whatwg-fetch/fetch.js /usr/share/nginx/html/node_modules/whatwg-fetch/fetch.js
Obviously, our web server will need to service both the index.html and the compiled Webpack bundle at dist/bundle.js to the users, so these are copied into the container image with COPY. However, from all the dependencies installed into the node_modules/ directory, our users will need only a very specific subset. For these reasons, we are copying these five files explicitly into the container image, instead of just using COPY for the entire node_modules/ directory.
Before actually building the container image, ensure that you have a recent Webpack build of your application and all dependencies installed. You can also use the -p flag to trigger Webpack to create a production build of your application that will be optimized for size:
$ webpack -p $ npm install
After this, build your container:
$ docker container build -t myevents/frontend .
You can now start this container using the following command:
$ docker container run --name frontend -p 80:80 myevents/frontend
Note that we are not passing the --network=myevents flag in this case. This is because the frontend container does not actually need to communicate with the backend services directly. All communication is initiated from the user's browser, not from within the actual frontend container.
The -p 80:80 flag binds the container's TCP port 80 to your local TCP port 80. This allows you to now open http://localhost in your browser and view the MyEvents frontend application. If you still have the backend containers from the previous sections running, the application should work out of the box.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
API Testing and Development with Postman by Dave Westerveld(3619)
Learning C# by Developing Games with Unity 2020 by Harrison Ferrone(2615)
Software Architecture for Busy Developers by Stéphane Eyskens(2322)
2021 Beginners Guide to Python Programming Language: A Crash Course to Mastering Python in One Hour by Elmer Gary & Elmer Gary(1884)
Machine Learning for Algorithmic Trading by Stefan Jansen(1629)
Hands-On ROS for Robotics Programming by Bernardo Ronquillo Japón(1572)
Delphi GUI Programming with FireMonkey by Andrea Magni(1457)
Game Development Projects with Unreal Engine by Hammad Fozi & Goncalo Marques & David Pereira & Devin Sherry(1402)
Cloud Native with Kubernetes by Alexander Raul(1374)
Datadog Cloud Monitoring Quick Start Guide by Thomas Kurian Theakanath(1347)
Software Architecture Patterns for Serverless Systems by John Gilbert(1338)
Practical Node-RED Programming by Taiji Hagino(1336)
Automate It with Zapier by Kelly Goss(1318)
Practical System Programming for Rust Developers by Prabhu Eshwarla(1312)
Delphi Programming Projects by William Duarte(1296)
Mastering React Test-Driven Development by Daniel Irvine(1290)
Developing Multi-Platform Apps with Visual Studio Code by Ovais Mehboob Ahmed Khan & Khusro Habib & Chris Dias(1253)
Ghidra Software Reverse Engineering for Beginners by A. P. David(1244)
Learn Spring for Android Application Development by S. M. Mohi Us Sunnat(1235)
