Is it possible create parent child Dockerfile and override the ENTRYPOINT?

Viewed 766

I create a DocherFile with OpenJDK base image and run init.sh script.

I want to inherit that Dockerfile and override the init.sh to test.sh script.

Is it possible to "test" docker file inherit from or extends "my-app" docker file and override ENTRYPOINT?

Should I define both "my-app" and "test" dockers in docker-compose? Can I run only test docker with docker-compose and not both?

My purpose is to run only "my-app" docker in production. But for tests, I want to extend it and run tests and some more configurations.

my-app/Dockerfile:

FROM openjdk:11-jre-slim
COPY initialization.sh /path/
ENTRYPOINT ["/bin/bash", "-c", "/path/init.sh"]

test/Dockerfile:

FROM my-app
COPY tset.sh /path/
ENTRYPOINT ["/bin/bash", "-c", "/path/tset.sh"]
1 Answers

Here is one idea,

You can have different docker-compose files.

  • docker-compose.yml: Contains the definition of all images needed for running your app.

    my-api:
      image: yourImage
      build:
        context: .
        dockerfile: Dockerfile
      depends_on:
        - sqldata
    
  • docker-compose.override.yml: Contains the base config for all images of the previous file.

     my-api:
      environment:
        - ENVIRONMENT=Development
        - DEBUG 
      ports:
        - "6105:80"
    

Using these two files together from CLI

docker-compose -f docker-compose.yml -f docker-compose.override.yml

This should start your app will all containers and the default environment by default.

PRODUCTION

docker-compose.prod.yml : This is a replacement of the docker.override but contains configurations, environment variables suitable for a production environment.

docker-compose -f docker-compose.yml -f docker-compose.prod.yml

TESTING Override the default entrypoint of the image

  • docker-compose-test.override.yml :

    app-test:
      environment:
        - ENVIRONMENT=Development
      ports:
        - "6103:80"
      entrypoint:
          - YourScript
          - memory=1
    
Related