我想将在Dockerfile中设置的PATH
和LD_LIBRARY_PATH
保存到.bashrc,以备将来使用。
但是,看来PATH
已正确保存,但LD_LIBRARY_PATH
未正确保存
例如,使用以下简单的Dockerfile将这些变量保存到临时文件中:
FROM nvidia/cuda:9.0-devel-centos7 AS devel
ENV PATH=/opt/pgi/linux86-64/18.4/bin:$PATH
ENV LD_LIBRARY_PATH=/opt/pgi/linux86-64/18.4/lib:$LD_LIBRARY_PATH
RUN touch mylibpath && \
touch mybinpath && \
echo $PATH >> mybinpath && \
echo $LD_LIBRARY_PATH >> mylibpath
结果是PATH
具有正确的值,而LD_LIBRARY_PATH
为空白,如下所示。
但是,如果我将LD_LIBRARY_PATH
重命名为ALD_LIBRARY_PATH
之类的内容,它将打印正确的值。
我想念什么?
================Before renaming =======================
$ sudo docker build --no-cache -t dshawul/acecast:latest .
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM nvidia/cuda:9.0-devel-centos7 AS devel
---> 96c10ed77499
Step 2/4 : ENV PATH /opt/pgi/linux86-64/18.4/bin:$PATH
---> Running in 2e3cf9a3ad64
---> cd56324327ab
Removing intermediate container 2e3cf9a3ad64
Step 3/4 : ENV LD_LIBRARY_PATH /opt/pgi/linux86-64/18.4/lib:$LD_LIBRARY_PATH
---> Running in d228c9421efc
---> 43c2d0043ff5
Removing intermediate container d228c9421efc
Step 4/4 : RUN touch mylibpath && touch mybinpath && echo $PATH >> mybinpath && echo $LD_LIBRARY_PATH >> mylibpath
---> Running in 52ba4a205815
---> e9aede6ab347
Removing intermediate container 52ba4a205815
Successfully built e9aede6ab347
Successfully tagged dshawul/acecast:latest
$ sudo docker run -it dshawul/acecast:latest
[root@efdfdcf693d9 /]# cat mybinpath
/opt/pgi/linux86-64/18.4/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[root@efdfdcf693d9 /]# cat mylibpath
[root@efdfdcf693d9 /]# exit
exit
==================After renaming ==============================
$ sudo docker build --no-cache -t dshawul/acecast:latest .
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM nvidia/cuda:9.0-devel-centos7 AS devel
---> 96c10ed77499
Step 2/4 : ENV PATH /opt/pgi/linux86-64/18.4/bin:$PATH
---> Running in 3628b77881b4
---> c98fc82bba60
Removing intermediate container 3628b77881b4
Step 3/4 : ENV ALD_LIBRARY_PATH /opt/pgi/linux86-64/18.4/lib:$ALD_LIBRARY_PATH
---> Running in 5eea6a5675c0
---> 7da3fb187682
Removing intermediate container 5eea6a5675c0
Step 4/4 : RUN touch mylibpath && touch mybinpath && echo $PATH >> mybinpath && echo $ALD_LIBRARY_PATH >> mylibpath
---> Running in ebdfdd5e3762
---> c175b1fbd2c1
Removing intermediate container ebdfdd5e3762
Successfully built c175b1fbd2c1
Successfully tagged dshawul/acecast:latest
$ sudo docker run -it dshawul/acecast:latest
[root@9cd1ed4fdf3a /]# cat mybinpath
/opt/pgi/linux86-64/18.4/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[root@9cd1ed4fdf3a /]# cat mylibpath
/opt/pgi/linux86-64/18.4/lib:
[root@9cd1ed4fdf3a /]# exit
exit
==========================================================
答案 0 :(得分:1)
在您的Dockerfile
中,如果仅将软件安装到/usr/bin
和/usr/lib
中的目录$PATH
和/etc/ld.so.conf
中,这是最简单的。由于您要描述的是将在隔离的文件系统中运行的内容上具有可复制性的生成过程,因此您实际上并不是在“污染已安装的操作系统”。
我已经看到some hints that Docker可能正在默默地剥离,忽略或重置LD_LIBRARY_PATH
环境变量,尽管我找不到明确的文档来这种效果。
答案 1 :(得分:1)
您的环境中还有其他事情在发生,可能是缓存的图像,因为我无法重现您的问题:
$ cat df.so-51670836
FROM nvidia/cuda:9.0-devel-centos7 AS devel
ENV PATH=/opt/pgi/linux86-64/18.4/bin:$PATH
ENV LD_LIBRARY_PATH=/opt/pgi/linux86-64/18.4/lib:$LD_LIBRARY_PATH
RUN touch mylibpath && \
touch mybinpath && \
echo $PATH >> mybinpath && \
echo $LD_LIBRARY_PATH >> mylibpath
$ docker build -t so-51670836 -f df.so-51670836 .
Sending build context to Docker daemon 23.04kB
Step 1/4 : FROM nvidia/cuda:9.0-devel-centos7 AS devel
---> 96c10ed77499
Step 2/4 : ENV PATH=/opt/pgi/linux86-64/18.4/bin:$PATH
---> Running in c152383485fd
Removing intermediate container c152383485fd
---> c47e029b5e50
Step 3/4 : ENV LD_LIBRARY_PATH=/opt/pgi/linux86-64/18.4/lib:$LD_LIBRARY_PATH
---> Running in b58a94b16980
Removing intermediate container b58a94b16980
---> 3c02bc748518
Step 4/4 : RUN touch mylibpath && touch mybinpath && echo $PATH >> mybinpath && echo $LD_LIBRARY_PATH >> mylibpath
---> Running in e81f4e821d28
Removing intermediate container e81f4e821d28
---> f5c5c2868350
Successfully built f5c5c2868350
Successfully tagged so-51670836:latest
$ docker run -it --rm so-51670836
[root@dfcb06ce3ac1 /]# cat my
mybinpath mylibpath
[root@dfcb06ce3ac1 /]# cat mylibpath
/opt/pgi/linux86-64/18.4/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64
[root@dfcb06ce3ac1 /]# cat mybinpath
/opt/pgi/linux86-64/18.4/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[root@dfcb06ce3ac1 /]# exit
exit
$ docker version
Client:
Version: 18.06.0-ce
API version: 1.38
Go version: go1.10.3
Git commit: 0ffa825
Built: Wed Jul 18 19:09:33 2018
OS/Arch: linux/amd64
Experimental: true
Server:
Engine:
Version: 18.06.0-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: 0ffa825
Built: Wed Jul 18 19:07:38 2018
OS/Arch: linux/amd64
Experimental: true