0

I am trying to do as the linked answer, but inside a dockerfile.

I have conda installed in the docker in the path /miniconda/bin. Entering bash in the docker and doing conda gives bash: conda: command not found. In that bash, manually doing export PATH="/miniconda/bin:$PATH" makes it know conda.

I want that in the dockerfile.

Whatever I try, /miniconda/bin is not added to the PATH.


Things I tried:

RUN export PATH="/miniconda/bin:$PATH" - PATH is not affected.

in the entrypoint script: export PATH="/miniconda/bin":$PATH - PATH is not affected.

How to make the PATH know conda?

Gulzar
  • 23,452
  • 27
  • 113
  • 201
  • Have you looked at how official Docker images are built? See [Miniconda Dockerfiles](https://github.com/ContinuumIO/docker-images/tree/master/miniconda3) or [Miniforge Dockerfile](https://github.com/conda-forge/miniforge-images/blob/master/ubuntu/Dockerfile). – merv Feb 14 '22 at 16:00

1 Answers1

2

Every RUN statement is it's own shell execution, so when the RUN command is done, any environment variables you set are lost. That's why RUN export doesn't work.

You can use the ENV statement to make it stick, like this

ENV PATH=/miniconda/bin:$PATH

Edit: My test of setting it. Dockerfile:

FROM debian:bullseye
ENV PATH=/my/path:$PATH

Build and run

docker build -t test .
docker run --rm test bash -c "echo $PATH"

Output:

/my/path:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Hans Kilian
  • 18,948
  • 1
  • 26
  • 35