概要
現在、DjangoでWebアプリケーションを作るにあたり、DockerとH2O、MariaDBを使ってdocker-compose環境を構築しています。
発生したエラー
H2OとGunicornでUNIXソケットを使って繋ぐ方法を試しているのですが、ファイルが見つからないというエラーが出てGunicornが起動しません。
エラーのログは以下の通りです。
log
1[2018-10-09 15:30:37 +0000] [284] [INFO] Booting worker with pid: 284 2[2018-10-09 15:30:37 +0000] [284] [ERROR] Exception in worker process 3Traceback (most recent call last): 4 File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker 5 worker.init_process() 6 File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 134, in init_process 7 self.run() 8 File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 124, in run 9 self.run_for_one(timeout) 10 File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 61, in run_for_one 11 self.notify() 12 File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 69, in notify 13 self.tmp.notify() 14 File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/workertmp.py", line 43, in notify 15 os.fchmod(self._tmp.fileno(), self.spinner) 16FileNotFoundError: [Errno 2] No such file or directory 17[2018-10-09 15:30:37 +0000] [284] [INFO] Worker exiting (pid: 284)
他の起動手段を試しても、同様のエラーが繰り返し表示されます。
コード
なお、このコードはGitHubのリポジトリ https://github.com/huideyeren/e-koto-3-server にあげてあります。
H2Oのコンテナはフォークしたリポジトリ https://github.com/huideyeren/h2o-proxy-letsencrypt を使っています。
とりわけ、 docker-compose.yml
は以下のようになっています。
YAML
1version: '3.4' 2 3volumes: 4 mysite.db.volume: 5 name: mysite.db.volume 6 7services: 8 h2o: 9 build: ./h2o 10 container_name: mysite.h2o 11 ports: 12 - "80:80" 13 - "443:443" 14 volumes: 15 - /var/run/docker.sock:/tmp/docker.sock:ro 16 - "./etc/letsencrypt:/etc/letsencrypt" 17 - ./static:/static 18 - ./tmp:/tmp 19 - ./tmp/django.sock:/tmp/django.sock:ro 20 depends_on: 21 - webapi 22 environment: 23 - EMAIL 24 - AGREEMENT=yes 25 26 db: 27 image: mariadb:10.3 28 container_name: mysite.db 29 ports: 30 - 3306:3306 31 environment: 32 MYSQL_ROOT_PASSWORD: mysitepass 33 TZ: 'Asia/Tokyo' 34 volumes: 35 - mysite.db.volume:/var/lib/mysql 36 - ./sql:/docker-entrypoint-initdb.d 37 38 webapi: 39 build: ./webapi 40 container_name: mysite.webapi 41 command: gunicorn e_koto_3.wsgi --bind=unix:/tmp/django.sock 42 volumes: 43 - ./src:/code 44 - ./static:/static 45 - ./tmp:/tmp 46 - ./tmp/django.sock:/tmp/django.sock 47 expose: 48 - "8000" 49 depends_on: 50 - db
また、 h2o.conf
はGoによるテンプレート部分も含めて以下の通りです。
Go
1--- 2user: root 3hosts: 4 "127.0.0.1.xip.io:80": 5 listen: 6 host: 0.0.0.0 7 port: 80 8 access-log: /dev/stdout 9 paths: 10 /: 11 proxy.reverse.url: http://[unix:/tmp/django.sock]/ 12 proxy.preserve-host: ON 13 proxy.timeout.keepalive: 0 14 "/static": 15 file.dir: /static 16 "127.0.0.1.xip.io:443": 17 listen: 18 host: 0.0.0.0 19 port: 443 20 access-log: /dev/stdout 21 paths: 22 /: 23 proxy.reverse.url: http://[unix:/tmp/django.sock]/ 24 proxy.preserve-host: ON 25 proxy.timeout.keepalive: 0 26 "/static": 27 file.dir: /static 28 29{{ define "proxy" }} 30 /: 31 proxy.preserve-host: ON 32 proxy.timeout.keepalive: 0 33 {{ if .Address }} 34 {{ if (and .Container.Node.ID .Address.HostPort) }} 35 proxy.reverse.url: "http://{{ .Container.Node.Address.IP }}:{{ .Address.HostPort }}" 36 {{ else }} 37 proxy.reverse.url: "http://{{ .Address.IP }}:{{ .Address.Port }}" 38 {{ end }} 39 {{ else }} 40 proxy.reverse.url: "http://{{ .Container.IP }} down" 41 {{ end }} 42{{ end }} 43 44{{ define "host" }} 45 "{{ .Host }}:{{ .Port }}": 46 listen: 47 host: 0.0.0.0 48 port: {{ .Port }} 49 {{ if (and .SSL (exists (printf "/etc/letsencrypt/live/%s/privkey.pem" .Host))) }} 50 ssl: 51 certificate-file: "/etc/letsencrypt/live/{{ .Host }}/fullchain.pem" 52 key-file: "/etc/letsencrypt/live/{{ .Host }}/privkey.pem" 53 {{ end }} 54 access-log: /dev/stdout 55 paths: 56 /.well-known/acme-challenge: 57 file.dir: /opt/data/{{ .Host }}/.well-known/acme-challenge/ 58 {{ template "proxy" .Proxy }} 59{{ end }} 60 61{{ define "hosts" }} 62 {{ if not .Test }} 63 {{ template "host" (dict "Host" .Host "Port" 80 "Proxy" .Proxy "SSL" (parseBool "false")) }} 64 {{ template "host" (dict "Host" .Host "Port" 443 "Proxy" .Proxy "SSL" (parseBool "true")) }} 65 {{ else }} 66 {{ template "host" (dict "Host" .Host "Port" 5002 "Proxy" .Proxy "SSL" (parseBool "false")) }} 67 {{ template "host" (dict "Host" .Host "Port" 5001 "Proxy" .Proxy "SSL" (parseBool "true")) }} 68 {{ end }} 69{{ end }} 70 71{{ $ACMETEST := (parseBool (coalesce .Env.ACME_TEST "false")) }} 72{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }} 73 74{{ if (ne $host "") }} 75hosts: 76{{ range $container := $containers }} 77 {{ $addrLen := len $container.Addresses }} 78 79 {{ if (eq $addrLen 1) }} 80 {{ $proxy := (dict "Container" $container "Address" (index $container.Addresses 0)) }} 81 {{ template "hosts" (dict "Host" $host "Proxy" $proxy "Test" $ACMETEST) }} 82 {{ else }} 83 {{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }} 84 {{ $addr := where $container.Addresses "Port" $port | first }} 85 {{ $proxy := (dict "Container" $container "Address" $addr) }} 86 {{ template "hosts" (dict "Host" $host "Proxy" $proxy "Test" $ACMETEST) }} 87 {{ end }} 88{{ end }} 89 90{{ end }} 91 92{{ end }}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/22 00:02