Cloud Native programming with Golang by Mina Andrawos
Author:Mina Andrawos
Language: eng
Format: epub, mobi
Publisher: Packt Publishing
Published: 2017-12-28T05:49:16+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
Cloud Native programming with Golang by Mina Andrawos.mobi
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.
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
Grails in Action by Glen Smith Peter Ledbrook(7696)
Configuring Windows Server Hybrid Advanced Services Exam Ref AZ-801 by Chris Gill(6536)
Azure Containers Explained by Wesley Haakman & Richard Hooper(6525)
Running Windows Containers on AWS by Marcio Morales(6049)
Kotlin in Action by Dmitry Jemerov(5062)
Microsoft 365 Identity and Services Exam Guide MS-100 by Aaron Guilmette(4896)
Combating Crime on the Dark Web by Nearchos Nearchou(4479)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4414)
Microsoft Cybersecurity Architect Exam Ref SC-100 by Dwayne Natwick(4308)
The Ruby Workshop by Akshat Paul Peter Philips Dániel Szabó and Cheyne Wallace(4155)
The Age of Surveillance Capitalism by Shoshana Zuboff(3946)
Python for Security and Networking - Third Edition by José Manuel Ortega(3715)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3503)
The Ultimate Docker Container Book by Schenker Gabriel N.;(3390)
Mastering Python for Networking and Security by José Manuel Ortega(3344)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3327)
Blockchain Basics by Daniel Drescher(3292)
Learn Wireshark by Lisa Bock(3229)
