如何从docker-compose链接到Amazon RDS

问题描述:

我的docker-compose.yml看起来像这样:

My docker-compose.yml looks something like this:

django:
  build: .
  user: django
  links:
    # LINK TO AMAZON RDS?
  command: /gunicorn.sh
  env_file: config/settings/.env

nginx:
  build: ./compose/nginx
  links:
    - django
  ports:
    - "0.0.0.0:80:80"

如何将django容器链接到Amazon RDS,后者的URL类似于:example.blahblahblah.eu-west-1.rds.amazonaws.com:5432

How do I link the django container to the Amazon RDS, which has an url like: example.blahblahblah.eu-west-1.rds.amazonaws.com:5432

在这种情况下,您不必定义链接";数据库服务已经在运行,因此您要做的就是配置django应用程序以连接到该主机.

In that case, you don't have to define a "link"; the database service is already running, so all you need to do, is configure your django app to connect to that host.

我没有django的经验,但是基于docker-compose文档中的示例,看起来像;

I don't have experience with django, but based on the example in the docker-compose documentation, it would look something like;

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'postgres',
        'USER': 'postgres',
        'HOST': 'example.blahblahblah.eu-west-1.rds.amazonaws.com',
        'PORT': 5432,
    }
}