-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
readme: add support for docker-compose #13
Conversation
Someone is attempting to deploy a commit to a Personal Account owned by @MaxLeiter on Vercel. @MaxLeiter first needs to authorize it. |
@katacarbix what if you add .env.local to the .dockerignore in server? Do you think that could fix the problem? |
The build fails with:
because obviously 'undefined' isn't a valid backend URL :) I've been mulling over it and I think the simplest solution would be to, instead of rewriting the URL on build, make a really simple server which serves the frontend for all requests except for ones to Maybe I'm overcomplicating it? Or maybe Next has a feature that does exactly that, I don't know. |
Next has support for a custom server (so you can use with it with e.g. express), but I prefer the front-end being completely separate so it can be served via providers like Vercel and Netlify. We could go with |
So I finally have a working solution which involves a separate nginx container. It assumes api links have been rewritten to I also commented the CORS header setting just for testing; I think in production we should use a trusted_proxies header instead. |
Can you try with |
@azlee91 Thank you for the suggestion, but that doesn't work for me. Is there anything you changed outside of I think the issue is that when the client sends a request to |
@katacarbix I just copied your docker-compose and changed the .env.local to use the Here's my docker-compose.yml, I removed a couple things I thought were not needed version: '3.8'
services:
server:
build: ./server
restart: unless-stopped
user: 1000:1000
environment:
- "PORT=3000" # probably not needed
- "JWT_SECRET=change_me!"
client:
build: ./client
restart: unless-stopped
user: 1000:1000
depends_on:
- server
ports:
- "3748:3001" |
Ohh I see what you mean. So you're using nginx proxy manager to fill the role that the proxy container currently plays? I use NPM too but I feel like it's easier to leave roles like this up to dedicated containers, even if it does consume slightly more resources :) I also think it makes more sense to provide an all-in-one solution in this repo that works out of the box, rather than expecting admins to know how to connect the two themselves. |
After some research, I guess this issue may be inaccurately titled. @katacarbix @azlee91, should a docker compose even be in the repo? Or should I just provide two docker images and let the sysadmin figure out connecting them? (Eventually, there will be docs to guide them). Docker-composes seem more system specific than I thought |
@MaxLeiter I suppose not, it's just a template to help you get started, and I think most of the time just putting it in the readme is sufficient enough. I can go ahead and do that if you'd like! |
@MaxLeiter I agree with @katacarbix, a minimum working example in say the "getting started" section would help people who want to just get it up and running to try it out |
@katacarbix that’d be great 🙏 |
Done! There is still the client env variables issue but that's a problem for another day. |
Sorry for the delay @reeseovine — i wanted to solve the env vars before merging but I’m now on vacation. I’ll get to this PR first thing when I’m back next week. Thanks again for your contribution 🙏 |
@MaxLeiter No worries! Enjoy your vacation 😄 |
@reeseovine I'm finally taking a swing at this, but am running into a problem: the client relies on the server to be started in order to build. Is it possible to have the |
@MaxLeiter There's the |
Yeah that’s what I’ve found, its just for starting afaict |
fwiw this is what I have
|
new docker-compose, but still running into issues with networking during build time: version: '3.4'
services:
server:
build: ./server
restart: unless-stopped
user: 1000:1000
environment:
- JWT_SECRET=change_me! # use `openssl rand -hex 32` to generate a strong secret
- SECRET_KEY=secret
expose:
- 3000
networks:
- general
healthcheck:
test: [ "CMD", "curl", "-s", "localhost:3000"]
interval: 10s
timeout: 45s
retries: 10
container_name: server
client:
build:
context: ./client
args:
API_URL: http://server:3000
restart: unless-stopped
user: 1000:1000
environment:
- API_URL=http://server:3000
- SECRET_KEY=secret
ports:
- "3001:3001"
networks:
- general
depends_on:
server:
condition: service_healthy
networks:
general:
driver: bridge |
Ok so I've made some progress but I still haven't solved the big issue of build/start order. I've brought back the Nginx proxy since the client needs to know the internet-accessible URL and path to the server and this takes care of some of the headache of that. docker-compose.yml: version: '3.4'
services:
server:
build:
context: ./server
network: host
restart: unless-stopped
user: 1000:1000
environment:
- JWT_SECRET=change_me! # use `openssl rand -hex 64` to generate a strong secret
- SECRET_KEY=secret
expose:
- 3000
healthcheck:
test: [ "CMD", "curl", "-s", "127.0.0.1:3000"]
interval: 10s
timeout: 45s
retries: 10
client:
build:
context: ./client
network: host
args:
API_URL: http://192.168.0.17/server-api
SECRET_KEY: secret
restart: unless-stopped
user: 1000:1000
environment:
- API_URL=http://192.168.0.17/server-api
- SECRET_KEY=secret
expose:
- 3001
depends_on:
server:
condition: service_healthy
proxy:
proxy:
image: nginx:alpine
restart: unless-stopped
volumes:
- "./nginx.conf:/etc/nginx/nginx.conf:ro"
ports:
- "80:80" The Nginx proxy needs to have the ip addresses of the server and client because it can't resolve their hostnames when they're down and throws an error. You can get these with nginx.conf: events {}
http {
server {
listen 80;
location / {
proxy_pass http://172.20.0.3:3001/;
}
location /server-api/ {
proxy_pass http://172.20.0.2:3000/;
}
}
} Here are the commands I've come up with to start this hacky setup:
Updating requires a bit more:
Now I'm really not sure this is a shippable solution. I think Docker-compose is just not designed for this kind of setup. I understand Docker is maybe not the primary target and you'd like to have first-class support for Vercel, I get it, but I think we'd need to do some more work on the client-server communication before it's Docker ready. |
@reeseovine I think the solution is just to admit defeat and provide two docker-composes, and treat the client and server as two independent services: |
Closing due to #75 Thanks a lot for your efforts here, @reeseovine! I'm excited to finally have this on Docker |
Fixes #6