0

I'm trying to set an Oracle environment variable inside the container.

I believe it is not running, because the files are not available on the OS.

Could anyone help?

Thank you so much

FROM node:lts-alpine
RUN mkdir -p /usr/src/app
COPY ./ /usr/src/app

WORKDIR /usr/src/app
RUN export LD_LIBRARY_PATH=/usr/src/app/instantclient_21_5:$LD_LIBRARY_PATH

CMD [ \"npm\", \"run\", \"start\" ]

When running the bash container. I try to run commands from the environment variable. Unsuccessfully.

marcelo.delta
  • 2,730
  • 5
  • 36
  • 71
  • I guess you have to use a docker-compose file. A user had a similar issue https://stackoverflow.com/questions/45440492/pass-host-environment-variables-to-dockerfile. Take a look at icc97's answer. – Klim Bim Feb 17 '22 at 12:18

1 Answers1

1

Trying to set an environment variable in a RUN statement doesn't make any sense: the commands in a RUN statement are executed in a child shell that exits when they are complete, so the effect of export LD_LIBRARY_PATH... aren't visible once then RUN statement finishes executing.

Docker provides an ENV directive for setting environment variables, e.g:

FROM node:lts-alpine
RUN mkdir -p /usr/src/app
COPY ./ /usr/src/app

WORKDIR /usr/src/app
ENV LD_LIBRARY_PATH=/usr/src/app/instantclient_21_5

CMD [ "npm", "run", "start" ]

Note that this can only be used to set static values (that is, you cannot include the value of another environment variable in the value -- you can't write ENV LD_LIBRARY_PATH=/usr/src/app/instantclient_21_5:$LD_LIBRARY_PATH). That should be fine because in this situation LD_LIBRARY_PATH should initially be unset.

(Also, you need to stop escaping the quotes in your CMD directive.)

larsks
  • 277,717
  • 41
  • 399
  • 399
  • The bit about using environment variables in an ENV statement is incorrect. You can do `ENV PATH=/my/path:$PATH` for instance. – Hans Kilian Feb 17 '22 at 12:36
  • 1
    In fact that won't do what you want: there is no `$PATH` defined in the current environment (or if there is, it has nothing to do with the container image you're building). You would typically want to do something like that at *runtime*, because you want the value of `$PATH` *as it is defined inside the container*. – larsks Feb 17 '22 at 12:37
  • I'm not the OP, if that's not clear. I just reacted to you saying that you can't use environment variables in ENV statements which you absolutely can. – Hans Kilian Feb 17 '22 at 12:40
  • That was clear, and I was pointing out the fallacy in your previous comment. That example doesn't make sense, and doing that generally won't give people the behavior they expect. – larsks Feb 17 '22 at 12:42
  • It gives me exactly what I expect. I'm not wise enough to speculate on what other people expect. – Hans Kilian Feb 17 '22 at 12:43