Dockerode: buildImage context not effective

Created on 19 Jan 2018  路  3Comments  路  Source: apocas/dockerode

I'm trying to build a Docker image whose dockerfile is in the parent directory. The dockerfile contains an ADD command:

# Copy files that need to live in the container into /app in the container
ADD ./app/container /app

I'm using this code to build the image

docker.buildImage({
  context: path.join(__dirname, '..'),
  src: ['Dockerfile'],
}, {
  t: 'tag-name'
}).then(out => out.pipe(process.stdout));

When it reaches the ADD command, it fails with the following error:

ADD failed: stat /var/lib/docker/tmp/docker-builder409481196/app/container: no such file or directory

Why is docker looking in this directory even after I've clearly specified the context?

I'm just trying to replicate the effect of docker build -t tag-name ..

Most helpful comment

Your context appears correct, however the docker daemon is building in a tmp directory and your files aren't copied along with it. I ran into a similar issue today and ended up using the tarball solution.

const tarfs = require('tar-fs');

const pack = tarfs.pack(path.join(__dirname, '..'));

docker.buildImage(pack, {
    t: 'tag-name'
}).then(out => out.pipe(process.stdout));

All 3 comments

Your context appears correct, however the docker daemon is building in a tmp directory and your files aren't copied along with it. I ran into a similar issue today and ended up using the tarball solution.

const tarfs = require('tar-fs');

const pack = tarfs.pack(path.join(__dirname, '..'));

docker.buildImage(pack, {
    t: 'tag-name'
}).then(out => out.pipe(process.stdout));

This is happening with me as well, I dont want to use tarball, any other fix for it?

+1 This is happening with me as well, I dont want to use tarball, any other fix for it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knight42 picture knight42  路  7Comments

hyperlink picture hyperlink  路  7Comments

zigmund picture zigmund  路  3Comments

ehsanshekari picture ehsanshekari  路  5Comments

florentvaldelievre picture florentvaldelievre  路  4Comments