0

I have the below working docker file:

# Use the Oracle SQLcl image as the base image
FROM container-registry.oracle.com/database/sqlcl:latest

# Set the current working directory
WORKDIR /app/

# Set the TNS_ADMIN environment variable
ENV TNS_ADMIN /opt/oracle/network/admin/

# Copy the TNSNAMES.ORA file into the container
COPY TNSNAMES.ORA $TNS_ADMIN/TNSNAMES.ORA
COPY scripts/ scripts/

# Login with AQTOPDATA
ENTRYPOINT ["sql", "mycredentials", "@scripts/script1.sql"]

However, I would like to parametrize @scripts/script1.sql to take scripts from a public repository, instead of being harcoded like that. For example, let's say there are the below files in an open repository:

script1.sql
script2.sql

I would like to be able to do something like (pseudo code) when I run the container:

docker run mycontainer --parameter https://github.com/repo/script2.sql

How can I achieve this?

MT0
  • 143,790
  • 11
  • 59
  • 117
Javi Torre
  • 724
  • 8
  • 23
  • Anything you pass after the `docker run image-name` is interpreted as the command to run, and is passed as arguments to the `ENTRYPOINT`. Could you write a script or larger program that has the behavior you need? – David Maze Feb 10 '23 at 14:27
  • (Style-wise, my general experience has been that you need to do a lot of work to marshal command-line arguments and input files in and out of containers like this; so if you just need to run an SQL client to import files that exist on the host, it might be much easier to just install the client program on your host system and run it directly, even if the server is in a container.) – David Maze Feb 10 '23 at 14:29
  • Could you please explain your idea further? I am not sure I am getting correct and I think it is a very interesting point. Ideally I would like to be able to execute whatever script by specifying it via parameter when running an already created container. – Javi Torre Feb 11 '23 at 16:32

1 Answers1

1

Just remove @script/script1.sql from your ENTRYPOINT, and put it in CMD, so that you have:

ENTRYPOINT ["sql", "mycredentials"]
CMD ["@scripts/script1.sql"]

If you just docker run myimage, it will run:

sql mycredentials @scripts/script1.sql

But if you run instead docker run myimage https://github.com/repo/script2.sql, then it will run:

sql mycredentials https://github.com/repo/script2.sql
larsks
  • 277,717
  • 41
  • 399
  • 399
  • Just an additional question: how can I run sql mycredentials https://github.com/repo/script2.sql but WITH authentication? – Javi Torre Feb 13 '23 at 08:28
  • Are you asking, "how do I authenticate to GitHub"? You should probably open a new question for that, because it's a different topic and it would be easier to address in an actual answer rather than in comments. – larsks Feb 13 '23 at 12:08
  • I have created https://stackoverflow.com/questions/75436050/call-sqlcl-script-hosted-in-a-private-repo-in-github Thanks for your help. – Javi Torre Feb 13 '23 at 12:44