Failed docker build at a copy step in Dockerfile

Wondering if this is an issue with docker version CircleCI uses or an issue with docker within the CircleCI platform. Based on my knowledge of Dockerfile commands, I don’t think I did there should be a problem with the dockerfile for various versions of docker?

The same Dockerfile builds fine locally on my Mac. I’m using the VirtualBox version of Docker on Mac, not the native Docker for Mac. Current running versions

  • Docker version 1.11.2, build b9f10c9
  • Kitematic 0.10.4
  • Electron 0.35.4

an excerpt of the Dockerfile steps:

//some build steps here

// Create app directory
RUN mkdir -p /opt/monitoring
COPY requirements.txt /opt/monitoring
COPY package.json /opt/monitoring
COPY Gemfile /opt/monitoring
WORKDIR /opt/monitoring

// Install dependencies & other support tooling
RUN bundle install
//more build steps including npm install, pip install -r requirements.txt

and I get this build failure in CircleCI

Step 19 : RUN mkdir -p /opt/monitoring
—> Running in 009a48e14c57
—> 4ca123622052
Error removing intermediate container 356d1270f773: no such id: 356d1270f773574f28202f8547e6887d08369b421f00bf5b00d868c7f9826864
Step 20 : WORKDIR /opt/monitoring
—> Running in bff4889222c2
—> 28ae381223f4
Error removing intermediate container 82012b83cf96: Cannot destroy container 82012b83cf9603aee696b05d72d062ba7168d9538a32537313373d043aab2c16: Driver btrfs failed to remove root filesystem 82012b83cf9603aee696b05d72d062ba7168d9538a32537313373d043aab2c16: Failed to destroy btrfs snapshot: operation not permitted
Step 21 : COPY requirements.txt /opt/monitoring
stat /var/lib/docker/btrfs/subvolumes/a2f0eb7958a0f9f50e367e4e9d9a1da76182d7e9a2721e369f7f6669d7f9c011/opt/monitoring/requirements.txt: not a directory

docker build -t repo/name . returned exit code 1

Action failed: docker build -t repo/name .

I suppose a workaround is to use RUN step to copy via Linux shell rather than the COPY command?

An update: using RUN + cp as workaround doesn’t seem to work either :frowning: and that’s worse than COPY because it fails locally and in CircleCI. At least with COPY, it just fails in CircleCI.

Here’s the excerpt:

Step 21 : RUN cp requirements.txt /opt/monitoring
—> Running in 3408f0409405
cp: cannot stat ‘requirements.txt’: No such file or directory
The command ‘/bin/sh -c cp requirements.txt /opt/monitoring’ returned a non-zero code: 1

I also observed CircleCI uses older version of Docker than what I’m using on my Mac. I wonder if that’s a reason for the inconsistency and failure in CircleCI?

Docker version 1.8.2-circleci-cp-workaround, build 4008b9c-dirty

I would think this isn’t hard to test/reproduce. Simply have a repo with python/ruby/node dependency setup files, create a specific (absolute) directory (and later set that was working directory), and copy the dependency setup files to the created directory, then run pip/gem/npm install.

The base image I use is phusion/passenger-customizable:0.9.18

I’m not aware of how to run multiple versions of Docker (on Mac) and don’t want to mess with my installation to try to test an older version of Docker to pinpoint this problem on the local side.

This error suggests that the opt/monitoring directory does not exist. Can you try adding mkdir before that copy command?

If you look at the original post, mkdir was already in the build step as listed and I also listed the runtime output

Step 19 : RUN mkdir -p /opt/monitoring

unless that command in CircleCI didn’t really do what it was supposed to do. As it works locally on Mac for me.

To aid in debugging and reproducing the issue, I created a demo public project:

if one forks this and build in CircleCI, it should reproduce the problem. And also feel free to test the docker build locally. It works on my Mac, would be interesting to find out which local environments will build it fine and which won’t (docker for Mac/Windows, docker on linux, etc.)

and here’s a sample build that failed

Well, my bad, got it working with a tip from a colleague. And reviewing the Dockerfile reference online, it appears the “proper” way to add/copy files to a directory is to add a trailing “/” for the directory. So I was doing it improperly all along.

Interesting though how it still works for docker on Mac but not in CircleCI. Weird of docker. Perhaps different versions/implementations are more lenient or strict with the dockerfile spec.

It’s sad that (technically) from the spec docker can’t “infer” a directory like how linux does even if you don’t supply a trailing forward slash. And why is it not picky about that trailing slash in other commands like WORKDIR (just because it doesn’t deal with files I guess)?

1 Like

Ah, I didn’t receive this update until after I forked your repo and reached the same conclusion.

It’s best to remember that multi-platform software is built to be consistent in its goals, but that cross-platform consistency is a “feature” that can have bugs just like any other feature. We have quite a few users who are, for instance, confused by Chrome or Firefox rendering bugs that exist only on Linux and not OS X.

For anyone else who finds this thread, note that an error such as:

stat /var/lib/docker/btrfs/subvolumes/a2f0eb7958a0f9f50e367e4e9d9a1da76182d7e9a2721e369f7f6669d7f9c011/opt/monitoring/requirements.txt: not a directory

could mean that Docker is expecting to copy a directory into another one and the source is not a directory. The more typical reading of this error message is that a parent directory in the destination doesn’t exist.

By the way, thank you so much for providing a minimal reproduction of the issue!