IBM Container Registries
In this lab we are going to create a Container Image and store it in the IBM Cloud Container Registry
Prerequisites
- IBM Cloud Account
Login into IBM Cloud
Using the IBM Cloud Shell
- Login into IBM Cloud
- Select correct account from top right drop down if your IBM id is associated with multiple accounts
- Click the IBM Cloud Shell Icon on the top right corner of the IBM Cloud Console
- This opens a new browser window with command linux terminal prompt.
Create a new Container Registry namespace
- Ensure that you're targeting the correct IBM Cloud Container Registry region. For example for Dallas region use us-south
- Choose a name for your first namespace, and create that namespace. Use this namespace for the rest of the Quick Start.Create a new Container Registry Namespace. This namespace is different from a Kubernetes/OpenShift namespace. The name needs to be all lowercase and globaly unique within a region.
Now set the environment
NAMESPACE
to be use for the rest of the lab
Building and Pushing a Container Image
- Clone the following git repository and change directory to
1-containers
- Inspect the file
Dockerfile
it contains a multistage build, first layer builds the application, the second copies only the built files.FROM registry.access.redhat.com/ubi8/nodejs-12 as base FROM base as builder WORKDIR /opt/app-root/src COPY package*.json ./ RUN npm ci COPY public public COPY src src RUN npm run build FROM base WORKDIR /opt/app-root/src COPY --from=builder /opt/app-root/src/build build COPY package*.json ./ RUN npm ci --only=production COPY --chown=1001:0 server server RUN chmod -R g=u server ENV PORT=8080 LABEL com.example.source="https://github.com/csantanapr/think2020-nodejs" LABEL com.example.version="1.0" ARG ENV=production ENV NODE_ENV $ENV ENV NODE_VERSION $NODEJS_VERSION CMD npm run $NODE_ENV
- Build and push the image, if not already set replace
$NAMESPACE
with the namespace you added previously, replaceus.icr.io
if using a different region.
Explore the Container Registry on the IBM Cloud Console
- Explore the container image details using the IBM Cloud Console. Go to the Main Menu->Kubernetes->Registry you can use the tabs
Namespaces
,Repository
,Images
Extra Credit (Run Imge on Kubernetes)
If you have a Kubernetes Cluster you can run your application image
- Get the Access token for your Kubernetes cluster, command assumes your cluster name is
mycluster
- Run the following commands to create a deployment using the image we just build. If not already set replace
$NAMESPACE
with your IBM Container Registry Namespace we stored the image. If the app is connected you should see the following output - Open a new Session and run the following command You should see in the first line of output the following
-
To access the app using a browser use the IBM Cloud Shell Web Preview. Click the Web Preview Icon and select port
8080
from the drop down. The application will open in a new browser window. -
To stop the application on the terminal with the
kubectl port-forward
command quit by pressing Ctrl+C in *Session 1
Delete Deployment and Image
- Delete the app deployment
- Delete the container image, if not already set replace
$NAMESPACE
with the registry namespace