官术网_书友最值得收藏!

Containerizing the KeystoneJS application

Follow these steps:

  1. Clone the repository in your development space: 
$ git clone https://github.com/legorie/gcpcookbook.git
  1. Navigate to the directory where the mysite application is stored:
$ cd gcpcookbook/Chapter01/mysite-gke  
  1. 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.

  1. 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
  1. The .dockerignore file contains the file paths which will not be included in the Docker container.
  2. 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.
  1. You can list the created Docker image:
$ docker images
  1. Push the created image to Google Container Registry so that our cluster can access this image:
$ gcloud docker --push gcr.io/<Project ID>/mysite  
主站蜘蛛池模板: 广河县| 进贤县| 钦州市| 龙口市| 迭部县| 阿克| 嘉荫县| 砚山县| 平罗县| 晋中市| 政和县| 微山县| 伊川县| 永善县| 达日县| 伊宁县| 阿坝| 兴安盟| 鹿泉市| 扎鲁特旗| 新巴尔虎右旗| 金堂县| 潜江市| 周宁县| 金门县| 海林市| 志丹县| 都兰县| 武隆县| 嘉荫县| 大姚县| 龙口市| 康平县| 西畴县| 偏关县| 盐源县| 原阳县| 房山区| 英山县| 关岭| 济阳县|