Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 初级码头工人_Django_Docker_Docker Compose_Gunicorn_Docker Machine - Fatal编程技术网

Django 初级码头工人

Django 初级码头工人,django,docker,docker-compose,gunicorn,docker-machine,Django,Docker,Docker Compose,Gunicorn,Docker Machine,我正在经历,我已经成功地建立并运行了堆栈 困扰我的是,当我在主机上更改代码时(在web服务中),当我在浏览器中重新加载页面时,会自动进行更改。我不明白它为什么这么做。这是我的docker compose.yml文件: web: restart: always build: ./web expose: - "8000" links: - postgres:postgres - redis:redis volumes: - ./web:/usr/s

我正在经历,我已经成功地建立并运行了堆栈

困扰我的是,当我在主机上更改代码时(在
web
服务中),当我在浏览器中重新加载页面时,会自动进行更改。我不明白它为什么这么做。这是我的
docker compose.yml
文件:

web:
  restart: always
  build: ./web
  expose:
    - "8000"
  links:
    - postgres:postgres
    - redis:redis
  volumes:
    - ./web:/usr/src/app
    - ./web/static:/usr/src/app/static
  env_file: .env
  environment:
    DEBUG: 'true'
  command: /usr/local/bin/gunicorn docker_django.wsgi:application -w 2 -b :8000

nginx:
  restart: always
  build: ./nginx/
  ports:
    - "80:80"
  volumes:
    - /www/static
  volumes_from:
    - web
  links:
    - web:web

postgres:
  restart: always
  image: postgres:latest
  ports:
    - "5432:5432"
  volumes:
    - pgdata:/var/lib/postgresql/data/

redis:
  restart: always
  image: redis:latest
  ports:
    - "6379:6379"
  volumes:
    - redisdata:/data


我不认为这是
gunicorn
进行重新加载,因为我认为
gunicorn
需要
--reload
标志才能真正进行热重新加载。

这一行表示您正在将主机上的位置映射到web容器中的位置

  volumes:
    - ./web:/usr/src/app
    - ./web/static:/usr/src/app/static

因此,无论何时更改.web目录中的代码,它都会在容器中更新。如果您不希望发生这种情况,那么在构建容器时,您需要通过在容器的Dockerfile中指定来复制这些目录。

谢谢,这很有意义。为什么gunicorn有一个
--reload
标志?而且,当使用诸如
waiteress
或甚至内置的django
runserver
等服务器时,几乎就好像需要重新加载代码才能真正反映代码一样。我相信这是因为您有环境变量
DEBUG:true
。这可能会影响Django中的
settings.py
,但为什么会影响提供文件的
gunicorn
  volumes:
    - ./web:/usr/src/app
    - ./web/static:/usr/src/app/static