Use script in docker compose

Dear all
i created one script file in test directory with full permission ,
my script is :

#!/bin/bash
docker cp /home/ojdc/ojdbc11.jar confluence-srv:/opt/confluence/confluence/WEB-INF/lib

then i write docker compose file :
my docker compose file is :

version: '3.4'
services:
  confluence:
    image: haxqer/confluence:8.4.2
    container_name: confluence-srv
    environment:
      - TZ=Asia/shanghai
    ports:
      - "8090:8090"
    volumes:
      - home_data:/var/confluence
    restart: always
    networks:
      - network-bridge
    command: ["/bin/bash", "-c", "/path to script/script.sh"]     
networks:
  network-bridge:
    driver: bridge
volumes:
  home_data:
    external: false

but after run docker compose up , ojdbc11.jar doesn’t copy with docker cp in my script with command tag in docker compose !!
please help me to resolved this issue !
thanks

I edited your post to add code blocks. Please, format your posts next time according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

I don’t get it. Where exactly are you trying to use that docker cp? I hope not in the “command” parameter in the compose file. That is for commands running inside the container.

And you don’t even need to copy if you can mount as you mount volumes. There are some examples here:

https://docs.docker.com/compose/compose-file/05-services/#volumes

Never copy files into a running container, especially not dependencies. Everything will disappear when you delete the container. You could create your own Dockerfile and build your own image that already has that dependency.

1 Like

Thanks for taking the time to edit my post and answer my question. i used docker cp for copy oracle driver to confluence container till connect my confluence container to oracle database. i test volume mount but this solution not working , i should used docker cp for copy this jar file (oracle driver) to container! but command tag not working for run script in docker compose ! how i can fix this issue?

Since I have already told you how you can fix this, please, share what you tried an so we can tell you what mistake you made.

As a reminder the two solutions:

1 Like

I know that solutions and i fix my problem with create custom docker image , but i want to learn how used script in docker compose if necessary!
many thanks for your attention

That’s not possible. You can run a script on the host and then run docker compose, but you can’§t run a script in docker compose.

1 Like

but i see someone run script in docker compose in stack overflow :

That runs in the container. Here is my tutorial about commands:

Compose is just another client for Docker

2 Likes

This is to thank you for devoting your time to answering my questions and helping me to increase my knowledge on this matter :pray: