I've been trying to update container PATH env variable value using docker commit --change ...
flag but I must be lacking understanding of some part involved as I'm unable to get desired result.
Given:
$ docker run -it centos:6 /bin/bash
[root@3b459018aa84 /]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
exit
Attempt 1:
$ docker commit -c "ENV PATH /usr/local/texlive/bin:${PATH}" 3b459018aa84 test-changes
$ docker run -it test-changes /bin/bash
[root@25116cd93d79 /]# echo $PATH
/usr/local/texlive/bin:/opt/local/bin:/opt/local/sbin:/Users/Ivan/.jenv/shims:/Users/Ivan/.jenv/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/share/dotnet:/opt/X11/bin
Resulting PATH seems to contain host machine's PATH value. I'm guessing it is because I used double quotes which caused ${PATH}
to be expanded before being passed to docker commit
.
Attempt 2:
$ docker commit -c 'ENV PATH /usr/local/texlive/bin:${PATH}' 3b459018aa84 test-changes
$ docker run -it test-changes /bin/bash
[root@c10a98a7fbce /]# echo $PATH
/usr/local/texlive/bin:
Attempt 3:
$ docker commit -c "ENV PATH=\"/usr/local/texlive/bin:${PATH}\"" 3b459018aa84 test-changes
$ docker run -it test-changes /bin/bash
[root@240c3e268d08 /]# echo $PATH
/usr/local/texlive/bin:/opt/local/bin:/opt/local/sbin:/Users/Ivan/.jenv/shims:/Users/Ivan/.jenv/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/share/dotnet:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
Attempt 4:
$ docker commit -c 'ENV PATH=\"/usr/local/texlive/bin:${PATH}\"' 3b459018aa84 test-changes
$ docker run -it test-changes /bin/bash
[root@bb10d27f1360 /]# echo $PATH
"/usr/local/texlive/bin:"
Attempt 5:
$ docker commit -c 'ENV PATH="/usr/local/texlive/bin:${PATH}"' 3b459018aa84 test-changes
$ docker run -it test-changes /bin/bash
[root@a683ab06f4d3 /]# echo $PATH
/usr/local/texlive/bin:
Attempt 6:
After reading docker commit
documentation one more time I saw --pause
flag. And so I tested a theory that pausing container affects access to the environment variables during commit.
$ docker commit -c 'ENV PATH="/usr/local/texlive/bin:${PATH}"' -p=false 3b459018aa84 test-changes
$ docker run -it test-changes /bin/bash
/usr/local/texlive/bin:
Nope, no luck either...
Desired output:
[root@c10a98a7fbce /]# echo $PATH
/usr/local/texlive/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
In other words I want the output to be as if ENV PATH /usr/local/texlive/bin:${PATH}
was added to Dockerfile.
I'm guessing I'm missing something silly and hopefully obvious to others but I'm out of ideas.
In case it comes to that, I'm running on Mac OS 10.13.2, Docker 17.12.0-ce-mac55 (23011).