tldr-version:我不知道是什么導致了這個錯誤。我很確定它不是行尾,因為我用記事本 手動更改了它們(除非我需要更改的內容超過 entrypoint.sh,因為這就是我更改行尾的全部內容)。
下面的原帖。
當我執行 docker-compose -f docker-compose-deploy.yml up --build 到我的命令列時,我不知道是什么導致了這個錯誤,我得到以下輸出
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Starting mygoattheend-copy_app_1 ... done
Starting mygoattheend-copy_proxy_1 ... done
Attaching to mygoattheend-copy_app_1, mygoattheend-copy_proxy_1
app_1 | exec /scripts/entrypoint.sh: no such file or directory
proxy_1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
proxy_1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
proxy_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
proxy_1 | 10-listen-on-ipv6-by-default.sh: info: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
proxy_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
proxy_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
proxy_1 | /docker-entrypoint.sh: Configuration complete; ready for start up
mygoattheend-copy_app_1 exited with code 1
proxy_1 | 2022/11/03 18:51:39 [emerg] 1#1: host not found in upstream "app" in /etc/nginx/conf.d/default.conf:9
proxy_1 | nginx: [emerg] host not found in upstream "app" in /etc/nginx/conf.d/default.conf:9
mygoattheend-copy_proxy_1 exited with code 1
當我搜索nginx: [emerg] host not found in upstream "app" in /etc/nginx/conf.d/default.conf:9 online 時出現的其他錯誤示例表明問題是由于缺少 -depends_on: 所以我在下面包含了我的 docker-compose 檔案,但我完美地遵循了教程并且他的作業正常。我的 docker-compose-deploy 有它的 -depends_on:
我完整的 docker compose 如下
version: '3.7'
services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./app:/app
command: sh -c "python manage.py runserver 0.0.0.0:8000"
environment:
- DEBUG=1
我完整的 docker-compose-deploy.yml 如下
version: '3.7'
services:
app:
build:
context: .
volumes:
- static_data:/vol/web
environment:
- SECRET_KEY=samplesecretkey123
- ALLOWED_HOSTS=127.0.0.1,localhost
proxy:
build:
context: ./proxy
volumes:
- static_data:/vol/static
ports:
- "8080:8080"
depends_on:
- app
volumes:
static_data:
下圖是我的完整目錄

該錯誤確實提到它找不到應用程式,我使用主 dockerfile 復制它(不是代理檔案夾中的那個)
我的主要 dockerfile 如下。
FROM python:3.8-alpine
ENV PATH="/scripts:${PATH}"
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers
RUN pip install -r /requirements.txt
RUN apk del .tmp
RUN mkdir /app
COPY ./app /app
WORKDIR /app
COPY ./scripts /scripts
RUN chmod x /scripts/*
RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/
RUN adduser -D user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web
USER user
CMD ["entrypoint.sh"]
什么可能導致此錯誤?
你還需要什么其他資訊來解決這個問題?
我正在關注本教程。我在最后
更新 4
新的 dockerfile 嘗試 dos2unix
FROM python:3.8-alpine
ENV PATH="/scripts:${PATH}"
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers dos2unix
RUN pip install -r /requirements.txt
RUN apk del .tmp
RUN mkdir /app
COPY ./app /app
WORKDIR /app
COPY ./scripts /scripts
RUN chmod x /scripts/*
RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/
RUN adduser -D user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web
USER user
CMD ["dos2unix", "entrypoint.sh"]
但我仍然得到同樣的錯誤。
更新 5
好的,所以我用記事本 手動更改了entrypoint.sh的eol,但我仍然得到同樣的錯誤。我需要將其應用于不僅僅是 entrypoint.sh 嗎?
uj5u.com熱心網友回復:
這個設定有兩個問題。
DOS 行尾
第一個問題是在入口點使用 DOS 行尾。這是我使用od逐字符轉儲檔案時看到的內容:
$ od -c scripts/entrypoint.sh | head -n 2
0000000 # ! / b i n / s h \r \n \r \n s e t
0000020 - e \r \n \r \n p y t h o n m a
問題是,之后#!/bin/sh,我們有\r\n,什么時候我們應該有\n。這是一個 DOS 風格的行尾,但 Linux 只需要一個\n. 更多資訊
我使用了一個名為 dos2unix 的程式來替換這些行:
$ dos2unix scripts/entrypoint.sh
dos2unix: converting file scripts/entrypoint.sh to Unix format...
(VS 代碼也可以做到這一點 -方法如下。)
當我運行它時,我收到一個新錯誤:
app_1 | Traceback (most recent call last):
app_1 | File "manage.py", line 21, in <module>
app_1 | main()
app_1 | File "manage.py", line 17, in main
app_1 | execute_from_command_line(sys.argv)
app_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
app_1 | utility.execute()
app_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 345, in execute
app_1 | settings.INSTALLED_APPS
app_1 | File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 76, in __getattr__
app_1 | self._setup(name)
app_1 | File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 63, in _setup
app_1 | self._wrapped = Settings(settings_module)
app_1 | File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 142, in __init__
app_1 | mod = importlib.import_module(self.SETTINGS_MODULE)
app_1 | File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
app_1 | return _bootstrap._gcd_import(name[level:], package, level)
app_1 | File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
app_1 | File "<frozen importlib._bootstrap>", line 991, in _find_and_load
app_1 | File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
app_1 | File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
app_1 | File "<frozen importlib._bootstrap_external>", line 843, in exec_module
app_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
app_1 | File "/app/app/settings.py", line 31, in <module>
app_1 | ALLOWED_HOSTS.extend(ALLOWED_HOSTS.split(',')) # .split(",") = incase multiple so we seperate them with a comma
app_1 | AttributeError: 'list' object has no attribute 'split'
設定檔案中參考了錯誤的變數
我編輯了檔案app/app/settings.py,并更改了這一行
ALLOWED_HOSTS.extend(ALLOWED_HOSTS.split(','))
至
ALLOWED_HOSTS.extend(ALLOWED_HOSTS_ENV.split(','))
在此之后,我發現這行得通。
Nginx
nginx 配置結果很好。問題是應用程式死了,所以 nginx 無法進行 DNS 查找來找到應用程式容器的 IP 地址。修復應用程式容器也修復了 nginx。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/529289.html
