我在Django网站上工作,在Linux Ubuntu服务器上部署它时,我遇到了一些问题:
我做了一个dockerfile(和docker compose文件),把它推到Docker Hub,从我的Linux服务器上拉出来,通过docker-compose启动这个docker镜像,然后我只看到PostgreSQL的日志(我甚至没有看到任何来自Django的错误)。我也尝试从其他计算机访问此网站,但它给我“ERR_CONNECTION_TIMED_OUT”错误。我会感激任何帮助!
(outtask是项目的名称)下面是我的Dockerfile代码:
FROM python:3.10
ENV PYTHONUNBUFFERED 0
WORKDIR /code
COPY ./requirements.txt .
RUN pip install --upgrade pip && pip install --upgrade setuptools wheel
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
下面是我docker-composer代码:
version: '3.9'
services:
db:
image: postgres
volumes:
- type: volume
source: pg_data
target: /var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
django:
image: django-docker:0.0.1
build: .
command: sh -c "gunicorn --bind 0.0.0.0:8000 outtask.wsgi:application"
# sh -c "python3 -u outtask/manage.py runserver 0.0.0.0:8000"
volumes:
- type: bind
source: .
target: /outtask
- type: volume
source: static_data
target: /outtask/static
ports:
- "8000:8000"
environment:
- DJANGO_SETTINGS_MODULE=outtask.settings
depends_on:
- db
volumes:
pg_data:
static_data:
www.example.com的代码settings.py你可以通过这个链接查找(不要看dockerfiles的奇怪位置,我已经在生产中修复了它):https://github.com/sh1nkey/outtask_v1/blob/main/outtask/outtask/settings.py
编辑:以下是Linux服务器上的Docker-compose文件的日志:
version: '3'
services:
web:
image: sh1nkey/outtask1:latest
ports:
- "80:80"
在linux服务器上启动项目时有日志:
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2023-05-19 12:30:29.719 UTC [47] LOG: starting PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2023-05-19 12:30:29.723 UTC [47] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-05-19 12:30:29.735 UTC [50] LOG: database system was shut down at 2023-05-19 12:30:29 UTC
2023-05-19 12:30:29.740 UTC [47] LOG: database system is ready to accept connections
done
server started
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
2023-05-19 12:30:29.825 UTC [47] LOG: received fast shutdown request
waiting for server to shut down....2023-05-19 12:30:29.827 UTC [47] LOG: aborting any active transactions
2023-05-19 12:30:29.829 UTC [47] LOG: background worker "logical replication launcher" (PID 53) exited with exit code 1
2023-05-19 12:30:29.830 UTC [48] LOG: shutting down
2023-05-19 12:30:29.833 UTC [48] LOG: checkpoint starting: shutdown immediate
2023-05-19 12:30:29.849 UTC [48] LOG: checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.005 s, sync=0.003 s, total=0.020 s; sync files=2, longest=0.002 s, average=0.002 s; distance=0 kB, estimate=0 kB
2023-05-19 12:30:29.853 UTC [47] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2023-05-19 12:30:29.946 UTC [1] LOG: starting PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 202101 10, 64-bit
2023-05-19 12:30:29.947 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port5432
2023-05-19 12:30:29.947 UTC [1] LOG: listening on IPv6 address "::", port 5432
2023-05-19 12:30:29.954 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-05-19 12:30:29.960 UTC [61] LOG: database system was shut down at 2023-05-19 12:30:29 UTC
2023-05-19 12:30:29.966 UTC [1] LOG: database system is ready to accept connections
- 尝试使用命令
docker run -t -p 8080:80 sh1nkey/outtask1
启动它-尝试更改docker-compose文件中的命令
1条答案
按热度按时间wbgh16ku1#
结案了这个错误是因为Docker Hub的错误标记,在这个问题存在的时候,我只有正在启动的db镜像。我只是重新标记了我的程序并按了i