I am having trouble with using a docker image I built.
SHELL ["/bin/bash", "--login", "-i", "-c"]
RUN apt update && apt upgrade -y && apt install curl -y
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
RUN source /root/.bashrc && nvm install 12.14.1
RUN nvm install 12.20.0
RUN apt install zip unzip
RUN curl -s "https://get.sdkman.io" | bash
RUN source "$HOME/.sdkman/bin/sdkman-init.sh"
RUN sdk install java 8.0.302-open
RUN sdk install gradle 3.4.1
SHELL ["/bin/bash", "--login", "-c"]
CMD [ "bin/bash" ]
After I run it, it says that npm is not found in $PATH, I tried Java, Gradle as well but they weren’t found in the path as well.
I don’t know why since I installed them as you can tell from the Dockerfile.
Any info on how to resolve this?
Basically I need an image with all dependencies for my app preinstalled so it can be used for building the app.
source "$HOME/.sdkman/bin/sdkman-init.sh" is responsible to set the proper paths to what is installed? If so, it must either be part of your CMD or an ENTRYPOINT script. If this is not the case, you will have to set the correct PATH using an ENV instruction in your Dockerfile.
Note: each RUN instruction will be executed in a new container, If a file is sourced or a process is started in a RUN instruction its outcomme will not be available in the following RUN instructions or the created container.
If that is the case with RUN instructions, then what is the use for them if only the latest will be baked into the image?
RUN instructions are to build the filesystem layers. Since you probably don’t use
source command to change files but to set variables in runtime, it will not work. Just imagine what happens when you set the variables in one terminal session it will not set the variables permanently.
This is why @meyay recommended running that source command in the entrypoint or command which runs when you start the container and not during build time. Or if you know the variables and the variables are not generated, you can use the ENV instruction which was also recommended by meyay. those environment variables are set in each temporary build container and also the final container which you can run from the image.