Home > other >  How can i access the host directory name of a volume?
How can i access the host directory name of a volume?

Time:10-23

I'm working on a Docker image that lints a Lua project, that is accessible by the container through a volume, the Dockerfile looks like this (the relevant part of it):

FROM debian:bullseye-slim
SHELL ["/bin/bash", "-O", "globstar", "-c"]

COPY --from=builder /usr/local/bin /usr/local/bin
COPY lint.sh /

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install --no-install-recommends gcc=4:10.2.1-1 luarocks=2.4.2 dfsg-1.1 -y && \
    rm -rf /var/lib/apt/lists/* && \
    luarocks install luacheck

CMD PROJECT_DIRECTORY=$(ls -d */ | grep -vE "bin|boot|dev|etc|home|lib|lib64|media|mnt|opt|proc|root|run|sbin|srv|sys|tmp|usr|var") && \
    cd $PROJECT_DIRECTORY && \
    stylua ./**/*.lua && \
    lua-format -i ./**/*.lua && \
    luacheck ./**/*.lua && \
    selene ./**/*.lua

And once the image is built, the container is invoked like this:

docker run -v $PWD:/<any-directory> <image>

The problem is, there's no way that i currently know of to get the <any-directory> name from inside the container, and i didn't wanted to pass a additional argument when running the container just for this, is there any practical way to accomplish such thing?

CodePudding user response:

Usually properties like the container paths or the port the container process will listen on are fixed when you build the image. As the image maintainer, you can pick whatever path you want; a typical choice in a Docker container would be /app. In the Dockerfile you can specify

WORKDIR /app

and assume that directory name is fixed; if you did need to bind-mount something there, anyone who used the image would always use /app as the second half of the docker run -v option.

  • Related