可以在Dockerfile中使用pushd/popd吗?

Aus*_*tin 9 dockerfile pushd

有没有办法在Dockerfile中使用pushd/popd命令?它会制作一些安装脚本,如果可能的话我会更容易.

Tho*_*eil 6

可以这样做,但您的图像必须具有 bash 并且所有命令都必须在同一RUN指令中:

文件

FROM debian
RUN mkdir -p /test/dir1/dir2
RUN bash -xc "\
pushd /test/dir1; \
pwd; \
pushd dir2; \
pwd; \
popd; \
pwd; \
"
RUN pwd
Run Code Online (Sandbox Code Playgroud)
Sending build context to Docker daemon  77.25MB
Step 1/4 : FROM debian
 ---> 2d337f242f07
Step 2/4 : RUN mkdir -p /test/dir1/dir2
 ---> Using cache
 ---> d609d5e33b08
Step 3/4 : RUN bash -xc "pushd /test/dir1; pwd; pushd dir2; pwd; popd; pwd; "
 ---> Running in 79aa21ebdd15
+ pushd /test/dir1
+ pwd
+ pushd dir2
+ pwd
+ popd
+ pwd
/test/dir1 /
/test/dir1
/test/dir1/dir2 /test/dir1 /
/test/dir1/dir2
/test/dir1 /
/test/dir1
Removing intermediate container 79aa21ebdd15
 ---> fb1a07d6e342
Step 4/4 : RUN pwd
 ---> Running in 9dcb064b36bb
/
Removing intermediate container 9dcb064b36bb
 ---> eb43f6ed241a
Successfully built eb43f6ed241a
Successfully tagged test:latest
Run Code Online (Sandbox Code Playgroud)