从docker-compose.yml覆盖Dockerfile ARG

时间:2018-02-15 12:00:49

标签: docker docker-compose

当我在Dockerfile arg中设置默认值时,我无法覆盖docker-compose.yml中的Dockerfile arg。

如果用户只是运行de Dockerfile whiteout任何我希望Docker不打破的参数,并且在docker-compose.yml上我想设置一个更好的架构。

这是我的Dockerfile:

FROM python:3.6 as flask_api
LABEL maintainer 'https://about.me/leandro.garcias'

ARG DEBUG=False
# BD Config
ARG DATABASE_URL='sqlite:///data/app.db'
# Max register per page, when you try to get all
ARG MAX_PER_PAGE=25
# Collect log errors. https://sentry.io
ARG COLLECT_LOG_ERRORS=False
ARG SENTRY_DSN=''

RUN adduser api
USER api

WORKDIR /home/api

COPY requirements.txt manage.py contrib/boot.sh ./
COPY tests tests
COPY app app

RUN mkdir data

ENV PYTHONUNBUFFERED 1
ENV DEBUG $DEBUG
ENV DATABASE_URL $DATABASE_URL
ENV MAX_PER_PAGE $MAX_PER_PAGE
ENV COLLECT_LOG_ERRORS $COLLECT_LOG_ERRORS
ENV SENTRY_DSN $SENTRY_DSN


RUN python -m venv venv
RUN venv/bin/pip install -r requirements.txt

CMD bash boot.sh

EXPOSE 5000:5000

这是我的docker-compose.yml:

version: '3'
volumes:
  local_data:
  data:
networks:
  web:
  app:
  db:
services:
  frontend:
    image: nginx:1.13
    volumes:
      - ./contrib/nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - 80:80
    networks:
      - web
      - app
    depends_on:
      - app
  app:
    image: flask_api
    restart: always
    volumes:
      - local_data:/home/api/data
    networks:
      - app
      - db
    depends_on:
      - db
    build:
      context: .
      args:
        - DEBUG = False
        # BD Config
        - DATABASE_URL = postgres://postgres:@db:5432/people
        # Max register per page, when you try to get all
        - MAX_PER_PAGE = 25
        # Collect log errors. https://sentry.io
        - COLLECT_LOG_ERRORS = False
        - SENTRY_DSN = ''
  db:
    image: postgres:9.6
    volumes:
      - data:/var/lib/postgresql/data
    networks:
      - db
    environment:
      - POSTGRES_DB=people

我需要帮助......

1 个答案:

答案 0 :(得分:2)

我找到了解决方案!只需要设置环境值。 : - )

  app:
    image: flask_api
    environment:
      - DEBUG=False
      # BD Config
      - DATABASE_URL=postgres://postgres:@db:5432/people
      # Max register per page, when you try to get all
      - MAX_PER_PAGE=25
      # Collect log errors. https://sentry.io
      - COLLECT_LOG_ERRORS=False
      - SENTRY_DSN=''