gilyes / docker-nginx-letsencrypt-sample

Dockerized Nginx + Let's Encrypt sample
https://gilyes.com/docker-nginx-letsencrypt
385 stars 185 forks source link

I get a strange error when starting my nginx-gen container #3

Open selenwall opened 7 years ago

selenwall commented 7 years ago

Have tried to figure this one out myself, but no. Seriously, it is not a directory.

nginx-gen | 2017/05/12 04:17:44 Unable to parse template: read /etc/docker-gen/templates/nginx.tmpl: is a directory nginx-gen | 2017/05/12 04:17:46 Error inspecting container: 0c1bc124d911f35483317010a5f55035df99452631ac19290a0e089b427c1641: No such container: 0c1bc124d911f35483317010a5f55035df99452631ac19290a0e089b427c1641 nginx-gen | 2017/05/12 04:17:46 Unable to parse template: read /etc/docker-gen/templates/nginx.tmpl: is a directory nginx-gen | 2017/05/12 05:08:01 Unable to parse template: read /etc/docker-gen/templates/nginx.tmpl: is a directory nginx-gen | 2017/05/12 05:08:02 Unable to parse template: read /etc/docker-gen/templates/nginx.tmpl: is a directory

gilyes commented 7 years ago

Assuming you are using the original docker-compose.yml, are you sure that ./volumes/proxy/templates/nginx.tmpl is present on the host machine? That is the file that is mapped to the container's /etc/docker-gen/templates/nginx.tmpl. If the host folder/file does not exist when running docker-compose up then the volume mapping will automatically create an empty folder with the name of that file, leading to the above error.

ivanistheone commented 7 years ago

The relevant part in the above error is: Unable to parse template: read /etc/docker-gen/templates/nginx.tmpl: is a directory letsencrypt-nginx-proxy-companion | Sleep for 3600s

I tried changing the line

  - "./volumes/proxy/templates/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro"

to

  - "./volumes/proxy/templates:/etc/docker-gen/templates:ro"

but doesn't seem to do the trick. Any ideas?

gilyes commented 7 years ago

As mentioned above, I've only seen this error when the file in question (./volumes/proxy/templates/nginx.tmpl) did not exist on the host and the volume mapping automatically created an empty directory using the same name as the file. Does ./volumes/proxy/templates/nginx.tmpl file (not directory) exist, relative to the directory of the docker-compose.yml file?

ivanistheone commented 7 years ago

I think this is an issue only when running the sample project on a remote docker host, e.g. one created by docker-machine.

One possible fix is to create a dummy container for the template file, see https://github.com/fle-internal/sushibar/commit/558c0e8886004b413b63d7fd80935384f024f6af

inspired by https://github.com/fatk/docker-letsencrypt-nginx-proxy-companion-examples/issues/5#issuecomment-213915895

gilyes commented 7 years ago

Makes sense, thanks for letting me know.

ivanistheone commented 7 years ago

To followup on that issue, it seems when using a remote host with docker-machine it is the user's responsibility to populate the volumes directory on the remote docker host (see https://stackoverflow.com/a/30512262/127114).

A workaround is to make the sample-website a self-contained Docker image so it won't depend on any volumes. This is how I did it: https://github.com/fle-internal/sushibar/commit/474fbd33a22eb6206ea52266f1f103b81e60d4a0

Note also I had to change VIRTUAL_NETWORK=nginx-proxy to VIRTUAL_NETWORK=<compose_proj_name>_default because otherwise nginx wasn't able to talk to sample-website.

Works great now! @gilyes thanks for saving me weeks figuring out this whole stack... very useful project, so happy I found it.