我正在尝试将Django应用程序部署到AWS ElasticBeanStalk。 Docker Compose在我的本地计算机上一切正常。但是,当它在AWS上运行时,它会给我以下信息: Image of error
docker-compose.yml:
version: '3'
services:
db:
image: postgres
hostname: db
app:
build:
context: .
dockerfile: config/app/Dockerfile
command: sh /config/on-container-start.sh
hostname: app
volumes:
- ./app:/app
expose:
- "8000"
depends_on:
- db
nginx:
image: nginx:latest
hostname: nginx
ports:
- "80:8000"
volumes:
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- app
Nginx
# define group app
upstream app {
# balancing by ip
ip_hash;
# define server app
server app:8000;
}
# portal
server {
# all requests proxies to app
location / {
proxy_pass http://app/;
}
# only respond to port 8000
listen 8000;
# domain localhost
server_name localhost;
}
在settings.py中:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
任何帮助将不胜感激, 谢谢
答案 0 :(得分:0)
您尝试过link
选项吗?
因此,您的撰写应如下所示:
version: '3'
services:
db:
image: postgres
hostname: db
app:
build:
context: .
dockerfile: config/app/Dockerfile
command: sh /config/on-container-start.sh
hostname: app
links:
- db
volumes:
- ./app:/app
expose:
- "8000"
depends_on:
- db
nginx:
image: nginx:latest
hostname: nginx
ports:
- "80:8000"
volumes:
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- app
links:
- app
选项depends on
用于在应用程序之前启动依赖项。