(Linux)

Build custom Docker images based on customization packages

We can build custom Docker images that include custom code or custom configurations, and then share and deploy the new images. If we are working on a local runtime environment for testing, development, or debugging purposes, we can use a temporary method to deploy changes to the local environment.

The following procedure teaches you how to:

  1. Create a Dockerfile for each type of Docker image.

  2. Create a docker-compose.yml file that references the Dockerfiles to build the new images.

At the end this procedure, you will have directories and files that resemble the following structure:


Procedure

  1. In a development environment, build customization packages (ts, store, search, xc) to include custom code.

  2. Download the customization packages to the runtime environment.

  3. Create separate CusDeploy directories for each Docker image to customize. For example,

    • /opt/WebSphere/db/CusDeploy (Applicable if running database in a Docker container)

    • /opt/WebSphere/search/CusDeploy

    • /opt/WebSphere/store/CusDeploy

    • /opt/WebSphere/xc/CusDeploy

    • /opt/WebSphere/app/CusDeploy

    • /opt/WebSphere/web/CusDeploy

  4. Extract any customization packages that were created from the WCB utility to the appropriate directory. For example,

    • Extract wcbd-deploy-server-ts-app.zip to /opt/WebSphere/app/CusDeploy.

    • Extract wcbd-deploy-server-crs-app.zip to /opt/WebSphere/store/CusDeploy

    • Extract wcbd-deploy-server-search-app.zip to /opt/WebSphere/search/CusDeploy

    • Extract wcbd-deploy-server-xc-app.zip to /opt/WebSphere/xc/CusDeploy

    For more information about building packages, see Building packages.

  5. Create or update a Dockerfile to build a new search-app Docker image.

    1. Create a Dockerfile in our search directory.

        /opt/WebSphere/search/Dockerfile

    2. Add the following text to the Dockerfile.

        FROM Docker_registry/commerce/search-app:source_image_tag
        HEALTHCHECK CMD curl -f http://localhost:3737
        COPY CusDeploy /SETUP/Cus
        RUN /SETUP/bin/applyCustomization.sh
        optional_commands

      Note: The HEALTHCHECK instruction checks the health of the application when the container is running. As the number of deployed containers grow, we might have to increase the HEALTHCHECK interval to avoid failures on check.

      • The FROM argument specifies which base Docker image to update.

      • The RUN argument references a shell script that instructs how to apply the customization package to the source image.

  6. Create or update a Dockerfile to build a new crs-app (Store) Docker image.

    1. Create a Dockerfile in the store directory. For example, /opt/WebSphere/store/Dockerfile

    2. Add the following text to the Dockerfile.

        FROM Docker_registry/commerce/crs-app:source_image_tag
        # Using yum in RHEL/CentOS for package installation
        RUN yum install -y nc && yum clean all
        HEALTHCHECK CMD nc localhost 8080 > /dev/null
        COPY CusDeploy /SETUP/Cus
        RUN /SETUP/bin/applyCustomization.sh
        optional_commands

  7. Create or update a Dockerfile to build a new ts-app (Transaction) Docker image.

    1. Create a Dockerfile in your app directory. For example, /opt/WebSphere/app/Dockerfile

    2. Add the following text to the Dockerfile.

        FROM Docker_registry/commerce/ts-app:source_image_tag
        RUN yum install -y nc && yum clean all
        HEALTHCHECK --retries=10 CMD nc localhost 5080 > /dev/nul
        COPY CusDeploy /SETUP/Cus
        RUN /SETUP/bin/applyCustomization.sh optional_commands

  8. Create or update a Dockerfile to build a new xc-app (Customization) Docker image.

    1. Create a Dockerfile in the store directory. For example, /opt/WebSphere/xc/Dockerfile

    2. Add the following text to the Dockerfile.

        FROM Docker_registry/commerce/xc-app:source_image_tag
        # Using yum in RHEL/CentOS for package installation
        RUN yum install -y nc && yum clean all
        COPY CusDeploy /SETUP/Cus
        RUN /SETUP/bin/applyCustomization.sh
        optional_commands

  9. Create or update a Dockerfile to build a new ts-web (Web) Docker image.

    1. Create a Dockerfile in your web directory. For example, /opt/WebSphere/web/Dockerfile

    2. Add the following text to the Dockerfile.

        FROM Docker_registry/commerce/ts-web:source_image_tag
        RUN yum install -y nc && yum clean all
        HEALTHCHECK --interval=10s CMD nc localhost 8000 > /dev/null
        #If we are using a local store from WebSphere Commerce Version 8 uncomment the next line.
        #COPY localStoreStaticAsset/ /SETUP/CUS/
        optional_commands

  10. Create or update a Dockerfile to build a new ts-db (Database) Docker image.

    Note: Applicable only if we are running the database in a Docker container.

    1. Create a Dockerfile in your db directory.

        /opt/WebSphere/db/Dockerfile

    2. Add the following text to the Dockerfile.

        FROM Docker_registry/commerce/ts-db:source_image_tag
        RUN yum install -y netcat && yum clean
        HEALTHCHECK --interval=20s CMD nc -z localhost 50000
        optional_commands

  11. Copy your existing docker-compose.yml file into the same directory that holds our Docker directories.

      /opt/WebSphere/docker-compose.yml

  12. Edit the docker-compose.yml file to add build and context parameters. For example,

        db:
          build:
            context: db
          image: docker_registry/commerce/ts-db:tag
          ...
      
        app:
          build:
            context: app
          image: docker_registry/commerce/ts-app:tag
          ...
      
        search:
          build:
            context: search
          image: docker_registry/commerce/search-app:tag
          ...
      
        store:
          build:
            context: store
          image: docker_registry/commerce/crs-app:tag
          ...
      
        web:
          build:
            context: web
          image: docker_registry/commerce/ts-web:tag
          ...

  13. Stop and remove the existing running containers.

  14. Build the new images.

    Note: To build and then deploy the containers in one command, we can use