Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
I have several stacks (i.e. applications) running on a server based on multiple docker-compose configurations. They all, by default, run on their own bridge network.
This is my current solution:
This works, but I don't know, if this is a recommended way.
Here I also have my configuration I'm using for WordPress:
There you can see, that I have one network for the apps internal communication (
Hope this helps you and maybe some others. :)
Is there an advantage to @RafaelKr's technique over just setting
networks: default: external: name: nginxproxy_default
Then you don't need a
version: '2' services: db: image: mariadb restart: unless-stopped environment: MYSQL_ROOT_PASSWORD: "change_me" MYSQL_DATABASE: "change_me" MYSQL_USER: "change_me" MYSQL_PASSWORD: "change_me" volumes: - ../data/docker/db:/var/lib/mysql wordpress: depends_on: - db image: RafaelKr/wordpress restart: unless-stopped hostname: change_me environment: VIRTUAL_HOST: www.change_me.dev WORDPRESS_DB_HOST: maria.db WORDPRESS_DB_NAME: "change_me" WORDPRESS_DB_USER: "change_me" WORDPRESS_DB_PASSWORD: "change_me" WORDPRESS_TABLE_PREFIX: "change_me" links: - db:maria.db volumes: - ../data/docker/wordpress:/var/www/html - ./src/themes:/var/www/html/wp-content/themes:ro - ../data/docker/logs:/var/log/apache2 networks: default: external: name: nginxproxy_default
Edit: I mean, I guess there is a security concern: now
version: '2' services: nginx-proxy: restart: always image: jwilder/nginx-proxy ports: - 80:80 networks: - nginxproxy volumes: - /var/run/docker.sock:/tmp/docker.sock:ro # this creates a network we can connect to in other docker-compose # files called `nginxproxy_default` as an *external* network (see other comment) networks: nginxproxy:
You can add in automatic SSL via Lets Encrypt with something like:
version: '2' services: nginx-proxy: restart: always image: jwilder/nginx-proxy container_name: proxy_nginx-proxy ports: - 80:80 - 443:443 networks: - nginxproxy volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - /etc/nginx/vhost.d - /usr/share/nginx/html - /data/letsencrypt-nginx-proxy-companion/certs/:/etc/nginx/certs:ro letsencrypt-nginx-proxy-companion: restart: always image: jrcs/letsencrypt-nginx-proxy-companion container_name: proxy_letsencrypt-nginx-proxy-companion volumes_from: - nginx-proxy volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - /data/letsencrypt-nginx-proxy-companion/certs/:/etc/nginx/certs:rw networks: nginxproxy:
I am using docker-compose for nginx-proxy and letsencrypt companion together.
This is my
Not sure if it is working really correctly as calling my VPS IP giving nginx 503 error.
Going further I have my wordpress container.
When I check nginx conf in nginx-proxy container, I see upstream but port never changes no matter what I put in expose or porst. I was trying many different combinations, always getting error (connection refused, not nginx page).
It redirects from http to https so something is happening but nothing correct...
shouldn't it be :
There seem to be two different issues here.
1. General docker-compose issues:
I found this repo, and it works flawlessly for me:
2. Run multiple applications on the same server with one proxy:
Unfortunately this is a docker-compose limitation. I've put together a simple example demonstrating how I've solved it (based on the above solution):
Since the nginx-proxy have access to the
There are codes in https://github.com/jwilder/nginx-proxy/blob/master/test/conftest.py already, can we reuse the code?
For anyone who's interested using docker-compose v3+ with nginx-proxy and docker-letsencrypt-nginx-proxy-companion and have problems setting up a container on https, here is a sample docker-compose.yml project.
Unlike if you start your containers with
In docker-compsoe v3+ we also have the problem, that the
version: '3.7' services: nginx-proxy: image: jwilder/nginx-proxy container_name: nginx-proxy restart: always ports: - 80:80 - 443:443 volumes: - conf:/etc/nginx/conf.d - vhost:/etc/nginx/vhost.d - html:/usr/share/nginx/html - certs:/etc/nginx/certs:ro - /var/run/docker.sock:/tmp/docker.sock:ro nginx-letsencrypt: image: jrcs/letsencrypt-nginx-proxy-companion container_name: nginx-proxy-letsencrypt restart: always volumes: - vhost:/etc/nginx/vhost.d - html:/usr/share/nginx/html - certs:/etc/nginx/certs - /var/run/docker.sock:/var/run/docker.sock:ro environment: NGINX_PROXY_CONTAINER: nginx-proxy phpmyadmin: image: phpmyadmin/phpmyadmin depends_on: - nginx-letsencrypt - nginx-proxy expose: - 80 environment: MYSQL_ROOT_PASSWORD: super_password VIRTUAL_HOST: your.dns.domain LETSENCRYPT_HOST: your.dns.domain volumes: conf: vhost: html: certs: networks: default: external: name: nginx-proxy