eugene-khyst / letsencrypt-docker-compose

Set up Nginx and Let’s Encrypt in less than 3 minutes with a Docker Compose project that automatically obtains and renews free Let's Encrypt SSL/TLS certificates and sets up HTTPS in Nginx for multiple domain names. Configuration is done using a simple CLI tool.
Apache License 2.0
473 stars 218 forks source link

Question about configuration and upstream #61

Closed NeekoDev closed 1 year ago

NeekoDev commented 1 year ago

Hi! First of all, thank you very much for this tool, I'm new to Docker and it's very enriching and it works perfectly as I wanted! 😃

I would just like to understand better this part of the documentation :

https://github.com/eugene-khyst/letsencrypt-docker-compose#2-3-2-2


I have a Nuxt 3 application in the example folder : /home/docker/letsencrypt-docker-compose/examples/docker-nuxt With a docker-compose.yml file.

But should I still add this (see below) in the docker-compose.yml at the root (/home/docker/letsencrypt-docker-compose) :

services:
  docker-nuxt:
    build: ./examples/docker-nuxt
    image: docker-nuxt
    restart: unless-stopped

Or do I just need to edit the docker-compose.yml from the example app with this (and remove above conf) :

version: "3"

services:
  docker-nuxt:
    build: ./examples/docker-nuxt
    image: docker-nuxt
    networks:
      - letsencrypt-docker-compose
    restart: unless-stopped

networks:
  letsencrypt-docker-compose:
    name: letsencrypt-docker-compose_default
    external: true

It's just a little confusing for me 😸 Thanks!

eugene-khyst commented 1 year ago

Hi @NeekoDev,

It depend on how many Docker Compose projects (different docker-compose.yml files) you want to have. In general, the most convenient way is to have a single Docker Compose project (a single docker-compose.yml file) and have Ngix, Certbot, Cron and Node.js containers there. But sometimes, developers already have an established repository for their Node.js application. It is still possible to build a Docker image from the Node.js app repo but reference it in the Let's Encrypt Docker Compose docker-compose.yml:

services:
  docker-nuxt:
    # build: ... this is not required as Docker image is build externally from another repo
    image: my-docker-nuxt-app:1.0.0 # name of the built Docker image
    restart: unless-stopped

But if you also need a database container (e.g. PostgreSQL), or cache (e.g. Redis), you probable will have a separate docker-compose.yml file in the Node.js app repo.

So, if you have 2 repositories: the first one for the Node.js repo with own docker-compose.yml and the second one Let's Encrypt Docker Compose with its docker-compose.yml, then follow the instruction in the section https://github.com/eugene-khyst/letsencrypt-docker-compose#2-3-2-2 of the documentation.

Otherwise, it's more convenient to have a single docker-compose.yml and define a service for your Node.js app there. Also note that you don't have to copy your Node.js app code to the examples/ dir or keep the code in the lets-encrypt-docker-compose dir at all.

You can have your Node.js app in it's own repo and build Docker image from it (e.g. docker build -t my-docker-nuxt-app:1.0.0 .). And in the lets-encrypt-docer-compose/docker-compose.yml add a service:

services:
  docker-nuxt:
    image: my-docker-nuxt-app:1.0.0
    restart: unless-stopped

Every time you make a change to your Node.js app, you have to build a new Docker image tag (e.g. docker build -t my-docker-nuxt-app:1.1.0 .). and update the tag in the lets-encrypt-docer-compose/docker-compose.yml:

services:
  docker-nuxt:
    image: my-docker-nuxt-app:1.1.0 # 1.0.0 --> 1.1.0
    restart: unless-stopped

Alternatively, you can keep you Node.js app source code in the lets-encrypt-docker-compose/examples/docker-nuxt dir (or rename examples to backend) and use in the docker-compose.yml:

services:
  docker-nuxt:
    build: ./examples/docker-nuxt
    image: docker-nuxt
    restart: unless-stopped

So, it all depend on how do you prefer to split the code between the Git repos, release it and deploy.

NeekoDev commented 1 year ago

Hi!

Thank you very much for this response! I understand how it works much better now. I'm going to see which method is best for my projects, I'm mainly in the testing and overall understanding of Docker phase.

Thank you 😃