Issue
tldr-version: I have no idea whats causing this error. im pretty sure its not the line endings because i changed them manually with notepad++ (unless i need to change more than entrypoint.sh because thats all i changed the line endings on).
original post below.
I have no idea what is causing this error caused when i do docker-compose -f docker-compose-deploy.yml up --build into my command line i get the following output
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
Other examples of errors that appear when i search for nginx: [emerg] host not found in upstream "app" in /etc/nginx/conf.d/default.conf:9 online suggest the problem is due to missing -depends_on: so ive included my docker-compose file below but i followed the tutorial perfectly and his worked fine. And my docker-compose-deploy has its -depends_on:
my full docker compose is below
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
My full docker-compose-deploy.yml is below
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:
the image below is my full directory
The error does mention that it can't find app, which i copy with the main dockerfile (not the one in the proxy folder)
My main dockerfile is below.
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"]
what could be causing this error?
what other info do you need to work it out?
im following this tutorial. im at the very end https://www.youtube.com/watch?v=nh1ynJGJuT8
update 1 (adding extra info)
my proxy/default.conf is below
server {
listen 8080;
location /static {
alias /vol/static;
}
location / {
uwsgi_pass app:8000;
include /etc/nginx/uwsgi_params;
}
}
my proxy/dockerfile is below
FROM nginxinc/nginx-unprivileged:1-alpine
COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY ./uwsgi_params /etc/nginx/uwsgi_params
USER root
RUN mkdir -p /vol/static
RUN chmod 755 /vol/static
USER nginx
update 2
this is my whole project uploaded to github https://github.com/tgmjack/help
update 3
editing the line endings in vscode didnt appear to work.
update 4
new dockerfile trying 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"]
but i still get the same error.
update 5
ok so i changed the eol of entrypoint.sh manually with notepad++ but i still get the same error. do i need to apply this to more than just entrypoint.sh?
Solution
There are two problems in this setup.
DOS line endings
The first problem is the use of DOS line endings on the entrypoint. Here's what I see when I use od
to get a character-by-character dump of the files:
$ 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
The issue is that after #!/bin/sh
, we have \r\n
, when we should have just \n
. This is a DOS-style line ending, but Linux expects just a \n
. More information
I used a program called dos2unix to replace those lines:
$ dos2unix scripts/entrypoint.sh
dos2unix: converting file scripts/entrypoint.sh to Unix format...
(VS code can do this too - here's how.)
When I run it, I get a new error:
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'
Wrong variable referenced in settings file
I edited the file app/app/settings.py
, and changed this line
ALLOWED_HOSTS.extend(ALLOWED_HOSTS.split(','))
to
ALLOWED_HOSTS.extend(ALLOWED_HOSTS_ENV.split(','))
After this, I found this worked.
Nginx
The nginx configuration turned out to be fine. The issue was that the app died, so nginx couldn't do a DNS lookup to find the IP address of the app container. Fixing the app container also fixes nginx.
Answered By - Nick ODell Answer Checked By - Senaida (WPSolving Volunteer)