hashicorp / hashicorp/consul-template

Generating template in docker for nginx

Open
#1,301 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
Go
Stars
4.8k
Forks
801
Avg merge
4h 5m
Merged PRs (30d)
6

Description

I went through this article and was able to get to this point with the help from the author. Article: https://danielparker.me/nginx/consul-template/consul/nginx-consul-template/

The issue is consul-template is not hot reloading the configuration and if I restart the container, it reads but returns erroneous information.

Issue 1: I've added -s reload flag but it's not taking any effect.

Issue 2: On force deleting and restarting the nginx (service) container, it reads the entry but returns
````
upstream department {
server 127.0.0.1:0;
}
````

### Dockerfile

````
FROM hashicorp/consul-template:alpine as template

FROM nginx
COPY --from=template /bin/consul-template /bin/consul-template

WORKDIR /service
COPY nginx.ctmpl nginx.ctmpl
COPY entrypoint.sh entrypoint.sh

ENTRYPOINT ["./entrypoint.sh"]

CMD nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
````

### entrypoint.sh

```shell
#!/bin/bash -x
echo "starting entry script"

consul-template -template "nginx.ctmpl:nginx.conf" -consul-addr "consul:8500" -log-level debug

exec "$@"
```

Tried `consul-template -template "nginx.ctmpl:nginx.conf -s reload" -consul-addr "consul:8500" -log-level debug` as well

### nginx.ctmpl

```
upstream department { {{range service "department" }}
server {{.Address}}:{{.Port}};{{end}}
}

server {
listen 80 default_server;

location /departments {
proxy_pass http://department
}
}
```

### docker-compose

```
version: '3'

services:

consul:
image: consul:1.6.1
container_name: consul
ports:
- 8300:8300
- 8400:8400
- 8500:8500

service:
container_name: nginx
build:
context: service
dockerfile: Dockerfile
ports:
- 8080:80
depends_on:
- consul
- department
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the setup with the Dockerfile, entrypoint.sh, nginx.ctmpl, and docker-compose configuration, then observe template changes and container restarts. Done means configuration changes trigger the intended reload and the generated upstream does not contain the erroneous 127.0.0.1:0 entry.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, nginx, shell
Domain
devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.