0

I am trying to evaluate cookiecutter-django, so far its a great tool to start a project. everything is going smooth except when I tried to use docker with certbot, i'm having this error.

nginx_1         | 2016/06/15 07:55:36 [emerg] 1#1: invalid port in upstream "___LETSENCRYPT_IP___:___LETSENCRYPT_PORT___" in /etc/nginx/nginx.conf:42

the start.sh contains

sed -i "s/___LETSENCRYPT_IP___/$LETSENCRYPT_PORT_80_TCP_ADDR/g" /etc/nginx/nginx.conf
sed -i "s/___LETSENCRYPT_PORT___/$LETSENCRYPT_PORT_80_TCP_PORT/g" /etc/nginx/nginx.conf

I'm not a guru here, but I can see that the script is referencing with environmental variables, but when i tried to inspect the enviromental variables in nginx container, I didn't see anything related to letsencrypt.

[root@localhost]# docker-compose run nginx bash
Starting tbpcsuite_certbot_1
Starting tbpcsuite_postgres_1
Starting tbpcsuite_redis_1
Starting tbpcsuite_django_1
root@b7d12c245b86:/# set
BASH=/bin/bash
BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="3" [2]="30" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu")
BASH_VERSION='4.3.30(1)-release'
COLUMNS=197
DIRSTACK=()
EUID=0
GROUPS=()
HISTFILE=/root/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/root
HOSTNAME=b7d12c245b86
HOSTTYPE=x86_64
IFS=$' \t\n'
LINES=73
MACHTYPE=x86_64-pc-linux-gnu
MAILCHECK=60
MY_DOMAIN_NAME=www.192.168.33.10.xip.io
NGINX_VERSION=1.11.1-1~jessie
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PIPESTATUS=([0]="1")
PPID=0
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
PS2='> '
PS4='+ '
PWD=/
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=1
TERM=xterm
UID=0
_=']'

I'm lost, any guidance I will appreciate.

Thanks,

leppy
  • 99
  • 1
  • 6
  • show content of nginx file at line 42 `/etc/nginx/nginx.conf:42` – Thanh Nguyen Van Jun 15 '16 at 09:05
  • proxy_pass http://___LETSENCRYPT_IP___:___LETSENCRYPT_PORT___; – leppy Jun 15 '16 at 09:14
  • in my understanding the start.sh should replace this line with $LETSENCRYPT_IP and $LETSENCRYPT_PORT, but environmental variables doesn't have them. – leppy Jun 15 '16 at 09:16
  • so you have to define `sed -i "s/___LETSENCRYPT_IP___/x.x.x.x/g" /etc/nginx/nginx.conf` with `x.x.x.x` is LETSENCRYPT IP ADDRESS – Thanh Nguyen Van Jun 15 '16 at 09:32
  • Yes, I agree with that, but my concern is regarding the environment variables in nginx container, I don't like to explicitly assign the IP, as docker might change it if I do rebuild. – leppy Jun 15 '16 at 09:49

1 Answers1

1

Looks like you may be using dockers new networking which deprecates the environmental variables for linked containers. Environment variables will only be populated if you’re using the legacy version 1 Compose file format.

I was able to get mine working by changing:

  • ___LETSENCRYPT_IP___ to certbot
  • ___LETSENCRYPT_PORT___ to 80
  • ___LETSENCRYPT_HTTPS_IP___ to certbot
  • ___LETSENCRYPT_HTTPS_PORT___ to 443

in both nginx.conf and nginx-secure.conf.

There's a discussion and an open pull request regarding this in the cookiecutter-django repo too, may have more info.

Dan
  • 11
  • 2