How to create a docker compose file with multiple dockerfiles?

Hi,

i have a solution with the following docker-compose file:

version: '3.6'
services:

 my_solr:
  container_name: mySolr
  volumes:
    - type: bind
      source: "/E:/Docker/Solr" 
      target: "/opt/solr/server/solr/mycores/myCore"
  image: solr:7.7.2
  ports:
   - "8983:8983" # to invoke the Solr admin console http://localhost:8983/ 
  entrypoint:
   - bash
   - "-c"
   - "precreate-core myCore; exec solr -f"
  networks:
   - app-net
 
 my_server:
  container_name: myServer
  environment:
   munixoserversettings: "someSettings"
  build: ./ # this build-command is using a already existing dockerfile
  ports:
   - "9898:9898" 
  depends_on:
   - my_solr 
  networks:
   - app-net
  volumes:
   - type: bind  
     source: "/E:/Docker/MyServer"
     target: "/usr/novimnt"  
networks:
 app-net:
 
volumes:
 v:

The first service my_solr has some commands in the entrypoint segment to prepare the container for a specific extension, it is called a “core”. The extension is a set of xml-files. Currently I insert them into the container by the following sequence:
1.) Invoke docker-compose with my docker-compose-file with the command “up”.
2.) Invoke
docker cp C:\Users\admin\Source\Repos\MySolrExtensions mySolr:/opt/solr/server/solr/mycores/
3.) Restart both containers.

I do not want to make the steps as described above. I want one docker-compose-file, that copies everything to the right place a that’s it.
Can I create a second Dockerfile that invokes the following

entrypoint:

  • bash
  • “-c”
  • “precreate-core myCore; exec solr -f”

and copies my extension to the image?

Thanks
Christian

I assume you have a directory, let’s call it project, which contains files docker-compose.yml and Dockerfile.

Create directory project/my_solr/extensions and copy all the files from C:\Users\admin\Source\Repos\MySolrExtensions to that new directory.

Then create file project/my_solr/Dockerfile with contents:

FROM solr:7.7.2
COPY extensions/* /opt/solr/server/solr/mycores/

ENTRYPOINT ["bash", "-c", "precreate-core myCore; exec solr -f"]

and change your docker-compose.yml to:

version: '3.6'
services:

 my_solr:
  container_name: mySolr
  volumes:
    - type: bind
      source: "/E:/Docker/Solr" 
      target: "/opt/solr/server/solr/mycores/myCore"
  build: ./my_solr
  ports:
   - "8983:8983" # to invoke the Solr admin console http://localhost:8983/ 
  networks:
   - app-net
 
 my_server:
  container_name: myServer
  environment:
   munixoserversettings: "someSettings"
  build: ./ # this build-command is using a already existing dockerfile
  ports:
   - "9898:9898" 
  depends_on:
   - my_solr 
  networks:
   - app-net
  volumes:
   - type: bind  
     source: "/E:/Docker/MyServer"
     target: "/usr/novimnt"  
networks:
 app-net:
 
volumes:
 v:

This should work unless you need bash -c precreate-core myCore; exec solr -f to run before your custom exceptions are copied.

Hi Konrad,
thanks a lot for yours help :upside_down_face:

FROM solr:7.7.2
COPY extensions/* /opt/solr/server/solr/mycores/

ENTRYPOINT ["bash", "-c", "precreate-core myCore; exec solr -f"]

I think, that I have to change the order from the above instructions like this:

1.) “bash”, “-c”, “precreate-core, myCore”
2.) COPY extensions/* /opt/solr/server/solr/mycores
3.) set Entrypoint to “exec solr -f”

Do you know how to achieve this?
Thanks a lot
Christian

What you need is:

FROM solr:7.7.2

RUN ["bash", "-c", "precreate-core myCore"]

COPY extensions/* /opt/solr/server/solr/mycores/

ENTRYPOINT ["exec solr -f"]

Be aware that RUN is only executed once during image build, while ENTRYPOINT is executed every time the container starts.

Hi Konrad,
thank you very much for yours help.
My “extensions” directory has a subfolder “myCore”, that contains some configuration files and subfolders.
The subfolder “myCore” including all containing subfolders and files should be copied to

/opt/solr/server/solr/mycores/myCore

What happens is, that the “myCore” folder is created, but the files are not copied into the “myCore” folder, instead they are copied to the same “level” as the folder “myCore”.

Do you have any idea?
Thanks
Christian

Have you tried:

FROM solr:7.7.2

RUN ["bash", "-c", "precreate-core myCore"]

COPY extensions/ /opt/solr/server/solr/mycores/

ENTRYPOINT ["exec solr -f"]

(without * in COPY)?

Hi Konrad,

yes, I tried the following options:

COPY /extensions/myCore /opt/solr/server/solr/mycores

or

COPY /extensions/* /opt/solr/server/solr/mycores/

=> The extensions are not copied into “myCore”. Instead the are on the same level.

COPY /extensions/myCore /opt/solr/server/solr/mycores/myCore

=> The extensions where not copied.

COPY /extensions/myCore/* /opt/solr/server/solr/mycores/myCore/
=> The directory “myCore” exists, but the extensions where not copied.

I suspect that the RUN command needs something more, to execute the “precreate-core myCore”.
To check this out I tried to execute solr already in the run, on the image build process. My idea was, that on the image the command (precreate-core myCore exec solr) is executed once and the core is created and ready to be filled with the extensions, that will be copied by starting the container.

FROM solr:7.7.2
RUN ["bash", "-c", "precreate-core myCore", "exec solr -f"] 
COPY /extensions/ /opt/solr/server/solr/mycores/
ENTRYPOINT ["bash", "-c", "exec solr -f"] 

Well, this does not work, too.
Do you have any idea?
Thanks a lot for your willingness to support.
Christian