2

I'm trying to install openssl from a Dockerfile manually. It's all working fine, until the last command source /etc/environment. I've tried RUN source /etc/environment inside my Dockerfile, and source /etc/environment in my entrypoint script but neither of them worked. But if I run the command manually inside a running container, it works fine. Any ideas why is this happening?

EDIT

This is the content of my Dockerfile. I don't have any errors building the image but the source doesn't seem to have any effect, unless I access the container and run it manually.

RUN wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz
RUN tar -xf openssl-1.1.1c.tar.gz
RUN cd openssl-1.1.1c; ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib; make; make test;  make install
RUN echo "/usr/local/ssl/lib" > /etc/ld.so.conf.d/openssl-1.1.1c.conf
RUN mv /usr/bin/c_rehash /usr/bin/c_rehash.backup
RUN mv /usr/bin/openssl /usr/bin/openssl.backup
RUN echo "PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/ssl/bin"" > /etc/environment
RUN source /etc/environment
Mehdi Khlifi
  • 405
  • 8
  • 21
  • can you please add the error details and also if possible the Dockerfile you are trying to build. – karan shah Oct 05 '20 at 16:44
  • 1
    Two big reasons: each `RUN` command runs in a new container, and any environment variables that get set there are lost; `source` isn't a standard shell command and on _e.g._ an Alpine base image it won't get recognized at all. You need to use the `ENV` directive to set environment variables that outlive a single command (or, better, restructure your image setup to install things into the "normal" system directories to not need special environment variables). – David Maze Oct 05 '20 at 16:47
  • @karanshah Hey, I've edited my question – Mehdi Khlifi Oct 06 '20 at 07:11
  • @DavidMaze If I log the container when it starts, the source command works fine and the command `openssl version -a` returns a result. But when I access the container, it returns `bash: openssl: command not found` – Mehdi Khlifi Oct 06 '20 at 09:14
  • You probably need to `RUN ldconfig`; it might be easier to use the base distribution's package manager to install OpenSSL. `/etc/environment` won't get used at all in a typical Docker setup. – David Maze Oct 06 '20 at 11:27
  • @DavidMaze I ended up adding `ENV PATH="/usr/local/ssl/bin:${PATH}" ` to my Dockerfile and it worked. What I still find odd, is that if I add the _source_ command and `openssl version -a` to my entrypoint, and I log my container when it starts, it's working fine, but if I access the container it returns command not found. Aren't commands ran in the entrypoint supposed to run once the container starts? – Mehdi Khlifi Oct 06 '20 at 13:53
  • "Access" like make an HTTP request? (`docker exec` is a _debugging_ tool; if you use it to launch a shell, it's not a child of the entrypoint process and doesn't see environment settings from there.) – David Maze Oct 06 '20 at 13:55

0 Answers0