I want to incorporate a virtual env in the docker container hence I’m trying to create a Conda environment (line 117-128) with the necessary dependencies needed for my use case which is in the environment.yml file. However, when I try to build the Dockerfile I get the following issue as mentioned in the title.
https://gist.github.com/impaidk/504363033b34406367e774c72544c540
The Dockerfile can be found in the above link.
After adding the lines 117 to 128 I get this problem.
Before adding these lines, I could successfully build the docker file. Can someone please direct me towards what am I wrongly doing here?
Removing intermediate container 426298ea76b6
---> 68c8b7342cc2
Step 36/54 : RUN echo "conda activate env_vis2mesh" >> ~/.bashrc
---> Running in 53949a223622
Removing intermediate container 53949a223622
---> 7635492d073b
Step 37/54 : SHELL ["/bin/bash", "--login", "-c"]
---> Running in 992f511d7842
Removing intermediate container 992f511d7842
---> aafcba711b55
Step 38/54 : RUN echo '[ ! -z "$TERM" -a -r /etc/motd ] && ( echo "cat <<EOF" ; cat /etc/motd ; echo EOF ) | sh' >> /etc/bash.bashrc
---> Running in 0ff2bb34ea36
Removing intermediate container 0ff2bb34ea36
---> 643f0f83bbd5
Step 39/54 : COPY motd /etc/
---> d10c760f8d25
Step 40/54 : USER $DOCKER_USER
---> Running in 9cc835cbdebb
Removing intermediate container 9cc835cbdebb
---> 819fae915c5f
Step 41/54 : RUN echo "umask 002" >> $DOCKER_HOME/.bashrc
---> Running in 9a24755e10ab
Removing intermediate container 9a24755e10ab
---> 5acb97493c3d
Step 42/54 : RUN echo "source $DOCKER_HOME/.version_information.sh" >> $DOCKER_HOME/.bashrc
---> Running in affb5a5086b1
Removing intermediate container affb5a5086b1
---> 101f71c5c403
Step 43/54 : COPY .version_information.sh $DOCKER_HOME
---> bc0bdd3b2437
Step 44/54 : RUN echo "if [[ -f $DOCKER_HOME/.bashrc-appendix ]]; then source $DOCKER_HOME/.bashrc-appendix; fi" >> $DOCKER_HOME/.bashrc
---> Running in badd158a5c1f
Removing intermediate container badd158a5c1f
---> cd42c89e893c
Step 45/54 : RUN mkdir -p $DOCKER_MOUNT_DIR/src
---> Running in 92dceb96a5f8
Removing intermediate container 92dceb96a5f8
---> d702d73b89f0
Step 46/54 : RUN mkdir $DOCKER_HOME/.ssh
---> Running in 463b4c55314b
Removing intermediate container 463b4c55314b
---> 49bc41c8e310
Step 47/54 : ADD templates $DOCKER_HOME/templates
---> d62e67ea2fc5
Step 48/54 : RUN echo 'export PATH=$PATH:$DOCKER_HOME/templates/bin' >> $DOCKER_HOME/.bashrc # using single quotes ensures that $PATH is not replaced here
---> Running in aee1b4ca57d9
Removing intermediate container aee1b4ca57d9
---> e119faed304a
Step 49/54 : USER root
---> Running in acc1ca160be5
Removing intermediate container acc1ca160be5
---> 6f3130f1a9a1
Step 50/54 : WORKDIR $DOCKER_MOUNT_DIR
cannot normalize nothing
2
Answers
By design, the environment variables declared in Dockerfile as
ENV
(and alsoARG
) are build-stage specific. And hence, whenever you start a new Docker build-stage (by using theFROM
parameter), the variables have to be declared once again as per your need.Just in case you’re wondering how the other
ENV
values such asDOCKER_USER
andDOCKER_HOME
are (seemingly) working in the newer build stages of your Dockerfile – they’re simply being set to null values which won’t throw any error during the build (but are surely going to give unpleasant surprises later!!).What it happens is docker can’t find environment variable $DOCKER_MOUNT_DIR so you can add a .env file in order to set this env. variable. Then, you must run
docker-compose up
to .env file works.Also, you can check more information in the official docker documentation about environment variables.