Dockerfile Does Not Set Environment Variable PATH [Duplicate]

Asked 2 years ago, Updated 2 years ago, 145 views

(3 answers) Two years ago

I am trying to deploy rbenv in a virtual environment using Docker, but I get an error when PATH is not passed in the rbenv install section.
The Dockerfile is as follows.

 FROM centos:centos7

# Install git
RUN yum-y install git

# Install rbenv
RUN git clone https://github.com/sstephenson/rbenv.git through /.rbenv
RUN echo'export PATH="$HOME/.rbenv/bin:$PATH"'>~/.bash_profile
RUN echo 'eval"$(rbenv init-)">>~/.bash_profile
RUN exec $SHELL-l
RUNecho$PATH
RUN git clone https://github.com/sstephenson/ruby-build.git through /.rbenv/plugins/ruby-build
RUN ["rbenv", "install", "-v", "2.2.3" ]
RUN ["rbenv", "rehash" ]
RUN ["rbenv", "global", "2.2.3" ]

The build run log is as follows:

Sending build context to Docker daemon 2.56 kB
Step 1: FROM centos: centos7
 --- > 0f0be3675ebb
Step 2: Maintenance Test
 --- > Using cache
 --->da0472c69ce1
Step 3: RUN yum-y install git
 --- > Using cache
 --- > 24b5366b0d4d
Step 4: RUN git clone https://github.com/sstephenson/rbenv.git~/.rbenv
 --- > Using cache
 --- > 1859d24d8942
Step5: RUN echo'export PATH="$HOME/.rbenv/bin:$PATH"'>~/.bash_profile
 --- > Using cache
 --- > 940d5514a25c
Step6: RUN echo'eval"$(rbenv init-)"'>>~/.bash_profile
 --- > Using cache
 --- > 747ad3b73095
Step 7: RUN exec $SHELL-l
 --- > Using cache
 --- >f2a32ad3625c
Step 8: RUN echo $PATH
 --- Running in 13448ff76c37
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
 --- >e4cf92d0f3e4
Removing intermediate container 13448ff76c37
Step 9: RUN git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
 --- > Running in 1309b521d2e2
Cloning into '/root/.rbenv/plugins/ruby-build'...
 --- >4c892315923a
Removing intermediate container 1309b521d2e2
Step 10: RUN rbenv install-v 2.2.3-p173
 --- Running inda7cc2ecf7e1
exec: "rbenv" —executable file not found in $PATH
Container command not found or does not exist.

I checked with echo$PATH on the way, but it seems that PATH is not working.
I would appreciate it if you could give me some advice.
Thank you for your cooperation.

docker rbenv

2022-09-30 19:21

1 Answers

  • Setting environment variables in Dockerfile uses ENV instead of RUN, which only takes effect until the end of the RUN.
  • through /.bash_profile are not loaded on non-login shells and are not loaded on each RUN.If you want to write environment variable settings like this one, I will use ENV.
  • If you use it as a Docker image, isn't the version control function of rbenv unnecessary.Apparently, using only ruby-build like this answer is sufficient.


2022-09-30 19:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.