- Google Cloud Platform Cookbook
- Legorie Rajan PS
- 359字
- 2021-08-27 19:13:25
Containerizing the KeystoneJS application
Follow these steps:
- Clone the repository in your development space:
$ git clone https://github.com/legorie/gcpcookbook.git
- Navigate to the directory where the mysite application is stored:
$ cd gcpcookbook/Chapter01/mysite-gke
- With your favorite editor, create a filename .env in the mysite folder:
PORT=8080 COOKIE_SECRET=<a very long string> MONGO_URI=mongodb://mongo/mysite
A custom port of 8080 is used for the KeystoneJS application. This port will be mapped to port 80 later in the Kubernetes service configuration. Similarly, mongo will be the name of the load-balanced MongoDB service that will be created later.
- The Dockerfile in the folder is used to create the application's Docker image. First, it pulls a Node.js image from the registry, then it copies the application code into the container, installs the dependencies, and starts the application. Navigate to /Chapter01/mysite-gke/Dockerfile:
# https://github.com/GoogleCloudPlatform/nodejs-getting-started/blob/master/optional-container-engine/Dockerfile # Dockerfile extending the generic Node image with application files for a # single application. FROM gcr.io/google_appengine/nodejs # Check to see if the version included in the base runtime satisfies # '>=0.12.7', if not then do an npm install of the latest available # version that satisfies it. RUN /usr/local/bin/install_node '>=0.12.7' COPY . /app/ # You have to specify "--unsafe-perm" with npm install # when running as root. Failing to do this can cause # install to appear to succeed even if a preinstall # script fails, and may have other adverse consequences # as well. # This command will also cat the npm-debug.log file after the # build, if it exists. RUN npm install --unsafe-perm || \ ((if [ -f npm-debug.log ]; then \ cat npm-debug.log; \ fi) && false) CMD npm start
- The .dockerignore file contains the file paths which will not be included in the Docker container.
- Build the Docker image:
$ docker build -t gcr.io/<Project ID>/mysite .
Troubleshooting:
- Error: Cannot connect to the Docker daemon. Is the Docker daemon running on this host?
- Solution: Add the current user to the Docker group and restart the shell. Create a new Docker group if needed.
- You can list the created Docker image:
$ docker images
- Push the created image to Google Container Registry so that our cluster can access this image:
$ gcloud docker --push gcr.io/<Project ID>/mysite
推薦閱讀
- 高效能辦公必修課:Word圖文處理
- 零起步輕松學(xué)單片機(jī)技術(shù)(第2版)
- 大學(xué)計(jì)算機(jī)信息技術(shù)導(dǎo)論
- Dreamweaver CS3+Flash CS3+Fireworks CS3創(chuàng)意網(wǎng)站構(gòu)建實(shí)例詳解
- Dreamweaver 8中文版商業(yè)案例精粹
- Windows XP中文版應(yīng)用基礎(chǔ)
- 大數(shù)據(jù)技術(shù)入門(第2版)
- Python Data Science Essentials
- 塊數(shù)據(jù)5.0:數(shù)據(jù)社會(huì)學(xué)的理論與方法
- Google SketchUp for Game Design:Beginner's Guide
- 工業(yè)機(jī)器人維護(hù)與保養(yǎng)
- LMMS:A Complete Guide to Dance Music Production Beginner's Guide
- Citrix? XenDesktop? 7 Cookbook
- Instant Slic3r
- Embedded Linux Development using Yocto Projects(Second Edition)