Docker-compose does not set environment variables

When I run docker-compose build && docker-compose up redis, with the environmentspecified in docker-compose.yamland RUN envin Dockerfile, the environment variables that I set are not printed.

Why is this not working?

I am using docker-composeversion 1.4.2.

Here are the relevant files:

docker-compose.yamlwith environmentas a list of pairs KEY=value:

redis:
    build: ../storage/redis
    ports:
      - "6379:6379"
    environment:
      - FOO='bar'

docker-compose.yamlwith environmentas a dictionary:

redis:
    build: ../storage/redis
    ports:
      - "6379:6379"
    environment:
      - FOO: 'bar'

Dockerfile:

FROM redis:2.6
MAINTAINER me@email.com

RUN mkdir -p /var/redis && chown -R redis:redis /var/redis

RUN echo '-------------- env ---------------'
RUN env

COPY redis.conf /usr/local/etc/redis/redis.conf
EXPOSE 6379
ENTRYPOINT ["redis-server", "/usr/local/etc/redis/redis.conf"]
+4
source share
1 answer

This is normal

docker-composesets only the environment variables specified in the directive environmentin the file docker-compose.yamlduring the container launch phase, and not during the build phase.

So, if you do docker-compose run --entrypoint "/bin/bash" redis -c env, you can see your env variables.

Docker ( ), RUN env:

ENV FOO bar
+3

Source: https://habr.com/ru/post/1611465/


All Articles