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:
I can't run my custom nginx container, named
nginxwithbuild: ./nginx/. onlyimage: nginx. Yes, I trydocker-compose buildas was suggested in thread.Strange behavior with volumes, I mentioned theese one:
- ./web:/codeand 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