Sterjakov
Sterjakov

Reputation: 87

How i can build container by docker-compose.yml environment variable?

How i can build container by docker-compose.yml environment variable?

For example, I try:

docker-compose.yml

version: '2'
services:
  web:
    build: .
    environment:
      RAILS_ENV: 'production'

Dockerfile

FROM isterjakov/nginx-passenger
# ...
#                           ↓↓↓↓↓↓↓↓↓↓
RUN echo "export RAILS_ENV='$RAILS_ENV'" >> /home/docker/.profile
# ...

But the variable still empty :( How i can do this?

Upvotes: 1

Views: 156

Answers (1)

Adrian Mouat
Adrian Mouat

Reputation: 46480

Try adding it as a build argument e.g:

version: '2'
services:
  web:
    build:
      context: .
      args:
        RAILS_ENV: 'production'

Personally however, I would only use Compose for running applications and do the build step separately.

Upvotes: 1

Related Questions