0

I've got the following dir tree:

project_root
|- build_script.sh
|- dir_1/Dockerfile and docker-compose.yml
|- tarball_dir/

I've got the build_script.sh which calls docker-compose like so:

docker-compose -f ./dir_1/docker-compose.yml build --build-arg BUILD_ID=$BUILD_ID dev

This is the Dockerfile:

 FROM elixir:1.5.2

  ARG BUILD_ID
  ENV APP_HOME /app
  RUN mkdir $APP_HOME

  # Copy release tarball and unpack
~ ADD ../dir_1/${BUILD_ID}.tar.gz $APP_HOME/

  CMD $APP_HOME/bin/my_app foreground

And this is the docker-compose-yml:

version: '2'

  services:
    common:
      build:
        context: .
        dockerfile: ./Dockerfile
      networks:
        - default

    dev:
      extends:
        service: common
      env_file:
        - ./dev.env
      environment:
        POSTGRES_HOST: "postgres.dev"
        MIX_ENV: dev
      ports:
        - "4000:4000"
      depends_on:
        - postgres

I want to be able to ADD (so that it copies and unpacks the tarball) into the image. However, after trying endless combinations of Docker context directories and trying to include the tarball into the image, I always get one of two errors:

ERROR: Service 'dev' failed to build: ADD failed: Forbidden path outside the build context: ../tarball_dir/tarball.tar.gz ()

or

ERROR: Service 'dev' failed to build: ADD failed: stat /var/lib/docker/tmp/docker-builder887135091/tarball_dir/tarball.tar.gz: no such file or directory

I would like to keep this directory structure, if possible. I've managed to build and run the container with the following command:

docker build \
--build-arg BUILD_ID=$BUILD_ID \
-t my_app:$BUILD_ID \
-f dir_1/Dockerfile .

docker run \
--network my_app_network \
--env-file ./dir_1/$ENV.env \
 my_app:$BUILD_ID

But I can't reproduce this same behaviour using docker-compose no matter what.

I'm on Mac OS Sierra and I'm using Docker Edge Version 17.10.0-ce-mac36 (19824) Channel: edge a7c7e01149

Sasha Fonseca
  • 2,257
  • 23
  • 41

0 Answers0