2

I have 3 containers with postgresql, nginx and django. The last two have their own Dockerfile, I run whole system with docker-compose. I have multiple problems:

  1. I can't run my custom nginx container, named nginx with build: ./nginx/. only image: nginx. Yes, I try docker-compose build as was suggested in thread.

  2. Strange behavior with volumes, I mentioned theese one: - ./web:/code and nothing work, i commented it, but now Django said me:


      /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'

My tree of files:

.
├── 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

My docker-compose file:

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/

And finally my both 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
Averin Maxim
  • 373
  • 4
  • 19
  • What is the error when you build it? Also `- ./web:/code` should be either `- .:/code` or `./web:/code/web` – Tarun Lalwani Aug 02 '17 at 09:56
  • @TarunLalwani during build I have no issues. When I change voulmes to `- .:/code` now it prints `python: can't open file 'manage.py': [Errno 2] No such file or directory`. I also switched to second option, but nothing happens – Averin Maxim Aug 02 '17 at 10:05
  • Please post a text output of of `pwd && ls -alh && docker-compose up --build` – Tarun Lalwani Aug 02 '17 at 10:08
  • @TarunLalwani https://pastebin.com/S8YncJXD – Averin Maxim Aug 02 '17 at 10:14
  • Your WORKDIR should be `/code/web` which has the manage.py file – Tarun Lalwani Aug 02 '17 at 10:21
  • @TarunLalwani I changed and python container always Exit – Averin Maxim Aug 02 '17 at 11:20
  • What's the new error? It should not be manage.py not found. It must have changed – Tarun Lalwani Aug 02 '17 at 11:29
  • @TarunLalwani `Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt' ERROR: Service 'site' failed to build: The command '/bin/sh -c pip install --no-cache-dir -r requirements.txt' returned a non-zero code: 1 `. If I changed path for requirements into `/code/web`, then manage.py not found – Averin Maxim Aug 02 '17 at 11:31

0 Answers0