Git Product home page Git Product logo

Comments (4)

bzoks avatar bzoks commented on July 29, 2024 1

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.

7-zete-7 avatar 7-zete-7 commented on July 29, 2024

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:

  1. 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
  1. 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
  1. 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.

JoppeDC avatar JoppeDC commented on July 29, 2024

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.

JoppeDC avatar JoppeDC commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.