0

EDIT to provide MRE:

Steps to reproduce (using Docker CLI, now, for reproducibility)

project_directory
   Dockerfile
   directory_to_cd_into
      gradlew

Dockerfile:

From debian:9

RUN cd /directory_to_cd_into
# also tried RUN cd ./directory_to_cd_into

Running docker build yields /bin/sh: 1: cd: can't cd to /directory_to_cd_into

So the problem is cd -- which means I must be missing something really basic about container directory structure.

Also tried WORKDIR

Happy to add more info.


Original:

From within my container, I can successfully build using gralde as follows:

cd directory/with/gradlew && chmod +x gradlew && ./gradlew build

But when I put this in my Dockerfile and try to build the container, it fails with "file or directory gradlew does not exist":

RUN cd directory/with/gradlew && chmod +x gradlew && ./gradlew build.

From this question, Unable to change directories while building docker Image using Dockerfile , I am aware that cd resets with every RUN statement -- but I'm doing this all from within a single RUN.

Everything prior to this RUN statement is held constant, i.e., if I comment out the RUN, and build interactively from the command line in the image, it builds fine.

If it matters, I'm doing all this from within a GitHub codespace; I'm not using the Docker CLI directly.

What am I doing wrong?

--

EDIT: I must be trying to include/cd directories from outside the build context. I'm not sure how to fix that yet -- maybe with COPY?

ultraGentle
  • 5,084
  • 1
  • 19
  • 45
  • Can you edit the question to include a [mcve]? When you run the container, are you using something like a bind-mount of a host source tree, where the runtime contents of the container are potentially different from what's in the image build? – David Maze Dec 14 '21 at 00:26
  • @DavidMaze done -- it's the `cd` that's erroring, so clearly there's something fundamental I'm not understanding about `cd`ing from *within* the container, which works, vs. from the Dockerfile, which doesn't. – ultraGentle Dec 14 '21 at 00:58
  • The Dockerfile you included doesn't `COPY` anything into the image, so there's nothing there to `cd` into. (`WORKDIR` will create the directory if it doesn't exist.) – David Maze Dec 14 '21 at 02:19

0 Answers0