Trying to build a dockerfile with alpine image and install set of directories. Here is the script below. It works fine until mkdir but does not change to /opt to download the git code.
The git code gets downloaded only to /src. Not sure whey the cd /opt command does not work.
FROM alpine
ADD . /src
WORKDIR /src
RUN apk update
RUN apk add git
RUN mkdir /opt
RUN cd /opt && git clone --recursive https://github.com/Azure/azure-iot-sdk-python.git
RUN ls -al
RUN cd azure-iot-sdk-python && ls -al build_all/linux
The current working directory is reset for every RUN
to the value of the last WORKDIR
.
So, because of that, this line RUN cd azure-iot-sdk-python && ls -al build_all/linux
is doing it from here /src
, and your cloned repo is in opt
.
So both of this will work:
RUN cd /opt/azure-iot-sdk-python && ls -al build_all/linux
and:
WORKDIR /opt
RUN cd azure-iot-sdk-python && ls -al build_all/linux
Robert是对的,您可以按照Dockerfile最佳实践来避免此问题,并且只有一个RUN,请参阅https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.