Change directory command in Docker?

后端 未结 3 1990
我在风中等你
我在风中等你 2020-12-04 10:23

In docker I want to do this:

git clone XYZ
cd XYZ
make XYZ

However because there is no cd command, I have to pass in the full path everytim

相关标签:
3条回答
  • 2020-12-04 10:40

    To change into another directory use WORKDIR. All the RUN, CMD and ENTRYPOINT commands after WORKDIR will be executed from that directory.

    RUN git clone XYZ 
    WORKDIR "/XYZ"
    RUN make
    
    0 讨论(0)
  • 2020-12-04 10:53

    You can run a script, or a more complex parameter to the RUN. Here is an example from a Dockerfile I've downloaded to look at previously:

    RUN cd /opt && unzip treeio.zip && mv treeio-master treeio && \
        rm -f treeio.zip && cd treeio && pip install -r requirements.pip
    

    Because of the use of '&&', it will only get to the final 'pip install' command if all the previous commands have succeeded.

    In fact, since every RUN creates a new commit & (currently) an AUFS layer, if you have too many commands in the Dockerfile, you will use up the limits, so merging the RUNs (when the file is stable) can be a very useful thing to do.

    0 讨论(0)
  • 2020-12-04 10:54
    RUN git clone http://username:password@url/example.git
    WORKDIR /folder
    RUN make
    
    0 讨论(0)
提交回复
热议问题