B
B
Bogdan2018-05-11 10:27:05
Docker
Bogdan, 2018-05-11 10:27:05

docker-compose build not seeing variables?

Hello. Tell me please. For some reason, when creating a container
docker-compose build
, it does not see the variable that is in the .env file.
APP_HOME=/coins
Here is a piece of docker-compose.yml where the file is connected

app:
    build: .
    command: >
      bash -c "
      bundle check
      || bundle install --clean
      && rm -f tmp/pids/server.pid
      && bundle exec rails db:migrate
      && bundle exec rails server"
    ports:
      - $PORT:$PORT
    volumes:
      - .:$APP_HOME
    environment:
      DATABASE_URL: postgresql://$POSTGRES_USER:[email protected]$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB?pool=$POSTGRES_POOL
      REDIS_PROVIDER: redis://:[email protected]$REDIS_HOST:$REDIS_PORT?db=$REDIS_DB
      BUNDLE_PATH: ${APP_HOME}/gems
    env_file:
      - .env
    depends_on:
      - db

Dockerfile
FROM ruby:2.5.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs vim

RUN mkdir $APP_HOME
WORKDIR $APP_HOME

And here is the error:
Building app
Step 1/4 : FROM ruby:2.5.1
 ---> 1624ebb80e3e
Step 2/4 : RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs vim
 ---> Using cache
 ---> a5d9b4e846ff
Step 3/4 : RUN mkdir $APP_HOME
 ---> Running in 0447e2436825
mkdir: missing operand
Try 'mkdir --help' for more information.
ERROR: Service 'app' failed to build: The command '/bin/sh -c mkdir $APP_HOME' returned a non-zero code:

5af5452c57a9f218998714.png
Of course, you can add a variable to the Dockerfile, but somehow I would like to have variables in one file.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-05-11
@bogdan_uman

So you shouldn't see it. Docker-compose inserts variables from .env only into docker-compose.yml
To pass them to the build, you can use this
https://docs.docker.com/compose/compose-file/#args

build:
  context: .
  args:
    APP_HOME: $APP_HOME

But I don’t see any reason to change the location of the application folder at all. It's an isolated container. do just /app
And another question, why do you need nodejs inside a container with ruby?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question