(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:
- Create a Dockerfile for each type of Docker image.
- 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:
+search ++Dockerfile ++CusDeploy +store ++Dockerfile ++CusDeploy +app ++Dockerfile ++CusDeploy +web ++Dockerfile +xc ++Dockerfile ++CusDeploy +db ++Dockerfile +docker-compose.yml
Procedure
- In a development environment, build customization packages (ts, store, search, xc) to include custom code.
- Download the customization packages to the runtime environment.
- 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
- 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.
- Create or update a Dockerfile to build a new search-app Docker image.
- Create a Dockerfile in our search directory.
/opt/WebSphere/search/Dockerfile
- 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.
- Docker_registry
- The Docker registry URL where the source image is located.
- source_image_name
- The name of the source image. For example, ts-app, ts-web, crs-app, search-app, xc-app.
- source_image_tag
- The tag of the source image to use.
- optional_commands
- (Optional) We can specify other commands to configure the application inside the Docker image. This can include using Run Engine commands or creating container start up scripts. For example, we can use Run Engine commands to set the data source so that the application can connect to the database.
- For more information about Run Engine commands, see Run Engine command framework.
- For more information about custom container start up scripts, see Docker container start up logic for 9.0.0.0 and 9.0.0.1.
- 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.
- Create or update a Dockerfile to build a new crs-app (Store) Docker image.
- Create a Dockerfile in the store directory. For example, /opt/WebSphere/store/Dockerfile
- 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
- Create or update a Dockerfile to build a new ts-app (Transaction) Docker image.
- Create a Dockerfile in your app directory. For example, /opt/WebSphere/app/Dockerfile
- 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
- Create or update a Dockerfile to build a new xc-app (Customization) Docker image.
- Create a Dockerfile in the store directory. For example, /opt/WebSphere/xc/Dockerfile
- 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
- Create or update a Dockerfile to build a new ts-web (Web) Docker image.
- Create a Dockerfile in your web directory. For example, /opt/WebSphere/web/Dockerfile
- 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
- 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.
- Create a Dockerfile in your db directory.
/opt/WebSphere/db/Dockerfile
- 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
- Copy your existing docker-compose.yml file into the same directory that holds our Docker directories.
/opt/WebSphere/docker-compose.yml
- 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 ...
- Stop and remove the existing running containers.
docker-compose -f docker-compose.yml rm
- Build the new images.
docker-compose -f docker-compose.yml build
Note: To build and then deploy the containers in one command, we can use
docker-compose -f docker-compose.yml up --build -d