Search code examples
docker

RUN pwd does not seem to work in my dockerfile


I am studying on Docker these days and confused that why RUN pwd just does not seem to work while running my docker file.

I am working on IOS

and the full content of my docker file can be seen as below:

FROM ubuntu:latest

MAINTAINER xxx

RUN mkdir -p /ln && echo hello world > /ln/wd6.txt

WORKDIR /ln

RUpwd

CMD ["more" ,"wd6.txt"]

as far as my understanding, after building the docker image with the tag 'wd8'and running it, I supposed the result should show like this

~ % docker run wd8
::::::::::::::
wd6.txt
::::::::::::::
hello world

ln

however, the fact is without ln.

I have tried with RUN $pwd, and also added ENV at the beginning of my dockerfile, both do not work.

Please help point out where the problem is.

ps: so I should not expect to see the directory 'ln' on my disk, right? since it is supposed to be created within the container...?

[enter image description here]

[1227]


Solution

  • There are actually multiple reasons you don't see the output of the pwd command, some of them already mentioned in the comments:

    • the RUN statements in your Dockerfile are only executed during the build stage, i.e. using docker build and not with docker run
    • when using the BuildKit backend (which is the case here) the output of successfully run commands is collapsed; to see them anyway use the --progress=plain flag
    • running the same build multiple times will use the build cache of the previous build and not execute the command again; you can disable this with the --no-cache flag