Comments (4)
We are using Traefik for this purpose - you can have any number of docker-compose projects, on each of them you add a "label" to docker-compose file with a hostname to which it should respond, and then Traefik is the only one listening on 80/443 and transferring traffic to actual HTTP servers (like Caddy). If you use whatever.localhost, then you even don't need to touch hosts file, as everything is by default automatically recognized and sent to proper container.
Look at Quick Start to see how easy you can set-it-up.
from symfony-docker.
Hello @JoppeDC!
You can use the 127.0.0.0/8
subnet to run multiple servers on the same port.
You will also have to configure the network for Docker so that applications can be launched on the necessary ports and make changes in /etc/hosts
.
Example by steps:
- Create new Docker networks
docker network create -o 'com.docker.network.bridge.host_binding_ipv4=127.0.10.1' app1
docker network create -o 'com.docker.network.bridge.host_binding_ipv4=127.0.10.2' app2
docker network create -o 'com.docker.network.bridge.host_binding_ipv4=127.0.10.3' app3
- Configure the
/etc/hosts
+ app1.localdomain www.app1.localdomain 127.0.10.1
+ app2.localdomain www.app2.localdomain 127.0.10.2
+ app3.localdomain www.app3.localdomain 127.0.10.3
- Configure the created networks in the
compose.override.yaml
files
services:
php:
+ networks: ["app1"]
...
database:
+ networks: ["app1"]
...
networks:
...
+ app1:
+ external: true
The created networks must be configured for all project containers. Each project should have its own network.
After this configuration, each of the projects will be launched on the same port, but have different host names (addresses). This will allow you to run multiple servers on the same port.
Reference:
from symfony-docker.
Thanks for this very fast reply @7-zete-7 !
This looks very promising. I did not know about host_binding_ipv4
, there's still much to learn when it comes to docker.
Although i'm unable to get this to work (I cant even visit the IP directly without the hosts config, which is not 1 to 1 because i'm using mac), it might be related to the fact i'm using Macos.
It seems like this caddy container is a cool and simple way to work on a single project, but quickly introduces a lot of complexities when using multiple projects. Which is why i find it a lil sad that this is the "Official" symfony method.
from symfony-docker.
For completeness, i'm gonna add how i resolved this, witgout the use of a proxy or networks.
So. Caddy NEEDS 80 and 443, when using it out of the box. This is because it automatically requests ssl etc.
Now, if you run it with docker auto generated ports, it doesnt work. Its internal config needs to map the port to the βsiteβ (as you would in eg. nginx or apache config).
So, what you can do, is provide your own certs (with mkcert, just add em to the repo), and run it on 2 other fixed ports. (Eg. 2015 for http and 20015 for https), you then need to configure these ports in the caddyfile as well for the caddy config, and boom, custom ports per project.
Only downside, you still need to define 2 ports in the .env file (i reuse those in docker and caddy config). So need to make sure every project has its own port defined
from symfony-docker.
Related Issues (20)
- cdn.jsdelivr.net importmap:install ERROR Curl HOT 4
- invalid interpolation format for services.php.environment.TRUSTED_HOSTS HOT 1
- Too stupid for recipes HOT 4
- Is mecure required for production? HOT 1
- Unable to connect to external database HOT 1
- Could this repo be converted to a symfony recipe? HOT 1
- Unable to boot app in production mode HOT 2
- Large number of entities cause ORM mapping to break HOT 9
- .env.prod.local not picked up on docker compose up HOT 4
- Unable to deploy in production HOT 3
- invalid interpolation format for services.php.environment.TRUSTED_HOSTS HOT 1
- Informations about my github ci file HOT 1
- Serving Symfony Welcome Page with Docker Compose Opens phpinfo() Instead HOT 2
- Cannot install some PHP extention HOT 1
- Docker escape error HOT 1
- container no run
- Mariadb Connexion lost HOT 5
- Symfony hanging every now & then HOT 17
- Unable to start existing project
- Franken crash HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from symfony-docker.