Home > Net >  Is there a way to run commands in a dockerfile?
Is there a way to run commands in a dockerfile?

Time:11-05

I am trying to append to the container Path from my dockerfile however when I build the docker file and run the container the changes I have made are not reflected in the container Path

RUN echo "export PATH=/go-dependencies:\$PATH:/home/skyctl/bin:/home/skyctl/.local/bin:/dependencies" >> ~/.bashrc

I ran the command above however none of the Paths added are reflected once the container is running

CodePudding user response:

You have to use a speciel layer-command for this in the Dockerfile instead of RUN. E.g.:

ENV PATH="${PATH}:/bin"

It's documented here as Environment Replacement

CodePudding user response:

Since the RUN line of the Dockerfile seems corrects, the issue is that you need to run the Docker image in interactive mode, such as:

docker run --name <yourimage> -it debian

This happens because during the build of the image the RUN command isn't interactive, so it isn't able to source the .bashrc file. When you build the Dockerfile, probably there will be warnings/info prompted in the logs that explain to you this.

  • Related