Docker-compose找不到.env文件

时间:2017-08-02 09:41:44

标签: django docker nginx docker-compose

我有3个带postgresql,nginx和django的容器。最后两个有自己的Dockerfile,我使用docker-compose运行整个系统。我有很多问题:

  1. 我无法使用nginx运行名为build: ./nginx/的自定义nginx容器。只有1个}}。是的,我按照thread中的建议尝试image: nginx

  2. 卷的奇怪行为,我提到了一个:docker-compose build但没有任何作用,我评论了它,但现在Django说我:

  3. 
          /usr/local/lib/python3.5/site-packages/environ/environ.py:609: UserWarning: /code/translation_microservice/.env doesn't exist - if you're not configuring your environment separately, create one.
          "environment separately, create one." % env_file)
        Traceback (most recent call last):
          File "manage.py", line 22, in 
            execute_from_command_line(sys.argv)
          File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
            utility.execute()
          File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 337, in execute
            django.setup()
          File "/usr/local/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
            apps.populate(settings.INSTALLED_APPS)
          File "/usr/local/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
            app_config.import_models()
          File "/usr/local/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
            self.models_module = import_module(models_module_name)
          File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in import_module
            return _bootstrap._gcd_import(name[level:], package, level)
          File "", line 986, in _gcd_import
          File "", line 969, in _find_and_load
          File "", line 958, in _find_and_load_unlocked
          File "", line 673, in _load_unlocked
          File "", line 673, in exec_module
          File "", line 222, in _call_with_frames_removed
          File "/code/api_controller/models.py", line 8, in 
            from web.translation import TranslatedLesson, TranslatedStep
        ImportError: No module named 'web'
    
    

    我的文件树:

    .
    ├── docker-compose.yml
    ├── nginx
    │   ├── Dockerfile
    │   └── nginx.conf
    ├── __pycache__
    ├── README.md
    ├── venv
    │   ├── bin
    │   ├── include
    │   ├── lib
    │   └── pip-selfcheck.json
    └── web
        ├── .env
        ├── Dockerfile
        ├── manage.py
        ├── requirements.txt
        └── translation
    

    我的docker-compose文件:

    version: '3'
    
    services:
      site:
        build: ./web
        env_file: ./web/.env
        # wanna do this
        #volumes:
        #  - ./web:/code
        command: python manage.py runserver 0.0.0.0:8000
    
      proxy:
        # wanna  build: ./nginx/
        image: nginx
        ports:
          - "80:80"
          - "443:443"
        volumes:
          - /www/static
    
      postgres:
        restart: always
        image: postgres:latest
        ports:
          - "5432:5432"
        volumes:
          - /var/lib/postgresql/data/
    

    最后我的两个Dockerfiles。 Django Dockerfile:

    FROM python:3.5
    ENV PYTHONUNBUFFERED 1
    
    RUN mkdir /code
    WORKDIR /code
    ADD ./requirements.txt /code/
    RUN pip install --no-cache-dir -r requirements.txt
    ADD . /code/
    
    EXPOSE 8000
    
    CMD ["/usr/local/bin/gunicorn", "translation_microservice.wsgi", "-w", "2", "-b", ":8000", "--access-logfile", "-", "--capture-output"]
    

    Nginx Dockerfile:

    FROM nginx:latest
    
    COPY ./nginx.conf /etc/nginx/nginx.conf
    

0 个答案:

没有答案