Skip to Content

SAP TechEd 2019 - Prepare Your Docker Container Image

0 %
SAP TechEd 2019 - Prepare Your Docker Container Image
// Explore More Tutorials

SAP TechEd 2019 - Prepare Your Docker Container Image


Configure and package your application into a Docker container image

You will learn

  • How to create your own Docker image with your application
  • How to upload your image into the container registry

These tutorials are meant to be completed at the Developer Garage at SAP TechEd. The experts at the Google Cloud booth will provide you with an access to an account.

Step 1: Create NPM configuration file

Use the following two commands to create a file called .npmrc in the srv directory. This file is used by NPM for configuration.

touch ~/teched/srv/.npmrc
edit ~/teched/srv/.npmrc
NPM config

Paste the following line into the file:

NPM config

Copy the .npmrc file to the root folder too with the following command:

cp ./srv/.npmrc ~/teched
Log on to answer question
Step 2: Create a Dockerfile

You will create a Docker image from a Node.js image using the application you created using the Cloud Application Programming model. This image will be uploaded into a repository and deployed into Cloud Run.

Create a Docker file using the following command:

touch ~/teched/Dockerfile
edit ~/teched/Dockerfile

Insert the following contents into the Dockerfile

# Use the official Node.js 8 image.
FROM node:8

# Create and change to the app directory.
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY /package*.json ./
COPY /srv/.npmrc .npmrc
COPY .npmrc ./

# Install dependencies.
RUN npm install

# Copy local code to the container image.
COPY . .

# Run the web service on container startup.
CMD [ "npm", "start" ]

NPM config
Log on to answer question
Step 3: Upload the image

Use the following command to create and upload a container image. Answer y if prompted to activate Cloud Run for your account.

cd ~/teched
gcloud builds submit --tag$GOOGLE_CLOUD_PROJECT/teched

For example:

NPM config

Make sure you see a SUCCESS message once the process is finished.

NPM config
Log on to answer question
Step 4: Retrieve the environment variable

Use the following command to get the VCAP_SERVICES environment variable.


Leave this open. You will need this result later.

NPM config

Log on to answer question
Step 5: Create a Cloud Run deployment

Open a new tab and enter

Click Create Service.

Create Cloud Run

Choose Select.

Create Cloud Run

Expand the list and click on the latest registry image.

Create Cloud Run

Flag Allow unauthenticated invocations and click Show optimal settings.

Create Cloud Run

In the environment variable, add a variable called VCAP_SERVICES and use the content of the result from echo $VCAP_SERVICES in the cloud shell:

Create Cloud Run

Scroll down and click Create

Create Cloud Run
Log on to answer question
Step 6: Test your service

Wait until deployment has finished and click on the URL.

Create Cloud Run

Congratulations! Your cloud run deployment is up and running.

Create Cloud Run

Click on the Foods service to complete the validation below.

Paste the results of the data exposed by the `Foods` service

Next Steps


  • These series of tutorials can be completed at the AppSpace at SAP TechEd.
  • You have completed the previous tutorial
Back to top