Docker Community Forums

Share and learn in the Docker community.

Override parent image docker container command to do something after

Issue type: Need help fixing docker-compose file
OS Version/build: Windows 10/Build 19042.928
Building on WSL Ubuntu 20.04.1 LTS
App version: (Docker version 20.10.5, build 55c4c88)
Steps to reproduce:
Run docker-compose up
Expect the file mentioned on the touch command to be created, but it does not happen.

I want to change a user password and run a SQL script against a DB2 container image. How do I do whatever the parent image called for, but then run a few commands after that completed? I need this to run using docker compose because the database will be used to support an acceptance test. In my docker-compose.yml file, I have a command property, but I checked the container and do not see the result of the touch statement, so it never ran.

My docker-compose.yml file is:

version: "3.2"
services:
  ssc-file-generator-db2-test:
    container_name: "ssc-file-generator-db2-test"
    image: ibmcom/db2:latest
    command: /bin/bash -c "touch /command-run && echo \"db2inst1:db2inst1\" | chpasswd && su db2inst1 && db2 -tvf /db2-test-scaffolding/init.sql"
    hostname: db2server
    privileged: true
#    entrypoint: ["/bin/sh -c ]
    ports:
      - 50100:50000
      - 55100:55000
    networks:
      - back-tier
    restart: "no"
    volumes:
      - db2-test-scaffolding:/db2-test-scaffolding
    env_file:
      - acceptance-run.environment
# ssc-file-generator:
#   container_name: "ssc-file-generator_testing"
#     image: ssc-file-generator
#     depends_on: ["ssc-file-generator-db2-test]
#     command: 
#    env_file: ["acceptance-run.environment"]

networks:
  back-tier: {}
volumes:
  db2-test-scaffolding:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./db2-test-scaffolding  

acceptance-run.environment

BCUPLOAD_DATASOURCE_DIALECT=org.hibernate.dialect.DB2Dialect
BCUPLOAD_DATASOURCE_DRIVER=com.ibm.db2.jcc.DB2Driver
BCUPLOAD_DATASOURCE_PASSWORD=bluecost
BCUPLOAD_DATASOURCE_URL=jdbc:db2://localhost:50100/mydb:currentSchema=FILE_GENERATOR
BCUPLOAD_DATASOURCE_USERNAME=bluecost
B2INSTANCE=db2inst1
DB2INST1_PASSWORD=db2inst1
DBNAME=MYDB
DEBUG_SECRETS=true
file-generator.test.files.path=src/test/acceptance/resources/files/
# Needed for DB2 container
LICENSE=accept

The docker image is

ibmcom/db2:latest

For convenience, this is the docker inspect ibmcom/db2:latest

[
    {
        "Id": "sha256:e304e217603b80b31c989574081b2badf210b4466c7f74cf32087ee0a1ba6e04",
        "RepoTags": [
            "ibmcom/db2:latest"
        ],
        "RepoDigests": [
            "ibmcom/db2@sha256:77da4492bf18c49a1012aa6071a16aee0039dca9c0a2a492345b6b030714a54f"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2021-03-29T18:54:36.94484751Z",
        "Container": "e59bda8065b72a0e440d145d6d90ba77231a514e811e66651d4fa6da98a34910",
        "ContainerConfig": {
            "Hostname": "6125cd0dc6e6",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "22/tcp": {},
                "50000/tcp": {},
                "55000/tcp": {},
                "60006/tcp": {},
                "60007/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "container=oci",
                "STORAGE_DIR=/database",
                "HADR_SHARED_DIR=/hadr",
                "DBPORT=50000",
                "TSPORT=55000",
                "SETUPDIR=/var/db2_setup",
                "SETUPAREA=/tmp/setup",
                "NOTVISIBLE=in users profile",
                "LICENSE_NAME=db2dec.lic"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "ENTRYPOINT [\"/var/db2_setup/lib/setup_db2_instance.sh\"]"
            ],
            "Image": "sha256:e65b35603167c75a86515ef4af101a539cbbdf561bcb9efd656d17b8d867c7da",
            "Volumes": {
                "/database": {},
                "/hadr": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "/var/db2_setup/lib/setup_db2_instance.sh"
            ],
            "OnBuild": [],
            "Labels": {
                "architecture": "x86_64",
                "build-date": "2021-03-10T06:09:00.139818",
                "com.redhat.build-host": "cpt-1007.osbs.prod.upshift.rdu2.redhat.com",
                "com.redhat.component": "ubi7-container",
                "com.redhat.license_terms": "https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI",
                "description": "The Universal Base Image is designed and engineered to be the base layer for all of your containerized applications, middleware and utilities. This base image is freely redistributable, but Red Hat only supports Red Hat technologies through subscriptions for Red Hat products. This image is maintained by Red Hat and updated regularly.",
                "distribution-scope": "public",
                "io.k8s.description": "The Universal Base Image is designed and engineered to be the base layer for all of your containerized applications, middleware and utilities. This base image is freely redistributable, but Red Hat only supports Red Hat technologies through subscriptions for Red Hat products. This image is maintained by Red Hat and updated regularly.",
                "io.k8s.display-name": "Red Hat Universal Base Image 7",
                "io.openshift.tags": "base rhel7",
                "name": "ubi7",
                "release": "338",
                "summary": "Provides the latest release of the Red Hat Universal Base Image 7.",
                "url": "https://access.redhat.com/containers/#/registry.access.redhat.com/ubi7/images/7.9-338",
                "vcs-ref": "a4e710a688a6374670ecdd56637c3f683d11cbe3",
                "vcs-type": "git",
                "vendor": "Red Hat, Inc.",
                "version": "7.9"
            }
        },
        "DockerVersion": "19.03.6",
        "Author": "db2_download_and_go",
        "Config": {
            "Hostname": "6125cd0dc6e6",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "22/tcp": {},
                "50000/tcp": {},
                "55000/tcp": {},
                "60006/tcp": {},
                "60007/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "container=oci",
                "STORAGE_DIR=/database",
                "HADR_SHARED_DIR=/hadr",
                "DBPORT=50000",
                "TSPORT=55000",
                "SETUPDIR=/var/db2_setup",
                "SETUPAREA=/tmp/setup",
                "NOTVISIBLE=in users profile",
                "LICENSE_NAME=db2dec.lic"
            ],
            "Cmd": null,
            "Image": "sha256:e65b35603167c75a86515ef4af101a539cbbdf561bcb9efd656d17b8d867c7da",
            "Volumes": {
                "/database": {},
                "/hadr": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "/var/db2_setup/lib/setup_db2_instance.sh"
            ],
            "OnBuild": [],
            "Labels": {
                "architecture": "x86_64",
                "build-date": "2021-03-10T06:09:00.139818",
                "com.redhat.build-host": "cpt-1007.osbs.prod.upshift.rdu2.redhat.com",
                "com.redhat.component": "ubi7-container",
                "com.redhat.license_terms": "https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI",
                "description": "The Universal Base Image is designed and engineered to be the base layer for all of your containerized applications, middleware and utilities. This base image is freely redistributable, but Red Hat only supports Red Hat technologies through subscriptions for Red Hat products. This image is maintained by Red Hat and updated regularly.",
                "distribution-scope": "public",
                "io.k8s.description": "The Universal Base Image is designed and engineered to be the base layer for all of your containerized applications, middleware and utilities. This base image is freely redistributable, but Red Hat only supports Red Hat technologies through subscriptions for Red Hat products. This image is maintained by Red Hat and updated regularly.",
                "io.k8s.display-name": "Red Hat Universal Base Image 7",
                "io.openshift.tags": "base rhel7",
                "name": "ubi7",
                "release": "338",
                "summary": "Provides the latest release of the Red Hat Universal Base Image 7.",
                "url": "https://access.redhat.com/containers/#/registry.access.redhat.com/ubi7/images/7.9-338",
                "vcs-ref": "a4e710a688a6374670ecdd56637c3f683d11cbe3",
                "vcs-type": "git",
                "vendor": "Red Hat, Inc.",
                "version": "7.9"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 2778060115,
        "VirtualSize": 2778060115,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/49d83ba2eb50cdbfc5a9e3a7b4baf907a9b4326aa0710689f602bb3cff01d820/diff:/var/lib/docker/overlay2/ba54659cc4ec10fa84edc49d5480ebe4897629f841d76ae79a4fb0c2edb791a5/diff:/var/lib/docker/overlay2/2238ae349d70686609b990b63c0066d6e51d94be59801a81c7f5b4d97da1fe02/diff:/var/lib/docker/overlay2/704708b72448f8a4750db3aabd43c12f23ad7e6d3f727aa5977bd7ac4db8e8cb/diff:/var/lib/docker/overlay2/1b47e1515517af553fd8b986c841e87d8ba813d53739344c9b7350ad36b54b0b/diff:/var/lib/docker/overlay2/0a580802a7096343aa5d8de5039cf5a011e66e481793230dced8769b024e5cd2/diff:/var/lib/docker/overlay2/4da91655770b0e94236ea8da2ea8ff503467161cf85473a32760f89b56d213ff/diff:/var/lib/docker/overlay2/401c640771a27c70f20abf5c48b0be0e2f42ed5b022f81f58ebc0810831283ea/diff:/var/lib/docker/overlay2/8985c59d1ab32b8d8eaf4c11890801cb228d47cc7437b3e9b4f585e7296e4b6a/diff:/var/lib/docker/overlay2/ec66f9872de7b5310bac2bd5fd59552574df56bb06dcd5dd61ff2b63002d77ed/diff:/var/lib/docker/overlay2/fcf40217c8477dcf4e5fafc8c83408c3c788f367ed67c78cb0bc312439674fcf/diff",
                "MergedDir": "/var/lib/docker/overlay2/8bcf7bf60181d555a11fb8df79a28cb2f9d8737d28fe913a252694ba2165c1d1/merged",
                "UpperDir": "/var/lib/docker/overlay2/8bcf7bf60181d555a11fb8df79a28cb2f9d8737d28fe913a252694ba2165c1d1/diff",
                "WorkDir": "/var/lib/docker/overlay2/8bcf7bf60181d555a11fb8df79a28cb2f9d8737d28fe913a252694ba2165c1d1/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:87e96a33b6fb724886ccda863dcbf85aab1119d380dc8d60fc7eeace293fc3a8",
                "sha256:7dfef4d05d0afc0383f5ebd8d9f3f7f7e17406f7e9e5744bead1a65e5ab47d0e",
                "sha256:51a646f7fd864ded24db2d87aaef69767cec8cfa63117bdca1a80cc4e0a77329",
                "sha256:9e2474c7feefaf8fe58cdb4d550edf725288c109f7842c819c734907406e9095",
                "sha256:d4d38bb7d4b3e7ea2b17acce63dd4b9ed926c7c0bbe028393228caf8933a4482",
                "sha256:4ec8c6264294fc505d796e17187c4c87099ff8f76ac8f337653e4643a9638d9e",
                "sha256:84a0a1068d25a8fa7b0f3e966b0313d31bc9e7405484da2a9ebf0fe1ebaf40dc",
                "sha256:956ab4664636dcce9d727ed0580f33ec510c8903ee827ce3ce72d4ba1184139b",
                "sha256:55f8b1bcde6acbd521024e3d10ed4a3a3bdf567cfd029b1876bd646ff502270b",
                "sha256:8c2496f1c442c3303273991e9cd5c4a5ffc0ab2ad7e2547976fe451095798390",
                "sha256:583acd9a453ded660462a120737ffec2def4416a573c6ea7ed2b132e403d9c08",
                "sha256:604c94797d42c86bfbc3d25e816a105b971805ae886bec8bc69bdae4ff20e1b6"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]