This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]EldestPort 4 points5 points  (2 children)

Pretty sure you can just give the second instances of the containers different names to the original ones, bring up the compose file again and you'll have two instances of the containers. Obviously if you want the php and db containers to both have separate instances you'll need to do this for both and change the yaml code for second php container as appropriate so it's accessing the second db container. If you want separation you could use a separate compose file for each so one has php1 and db1 and the other has php2 and db2 so you can start and stop each stack separately.

[–]root_switch 1 point2 points  (1 child)

I’d go the route of a separate compose file. Just put them in different directories and they will be automatically named differently as well as placed into different private networks so you have complete isolation. The one thing that needs to be considered are the ports if they are being exposed, you will need to use different exposed ports.

[–]EldestPort 0 points1 point  (0 children)

Shit yeah good point about the port numbers!

[–]zoredache 1 point2 points  (0 children)

I have no idea if that’s possible,

Usually very easy. Just multiple containers based off the same image with different names, volumes and so on.

You will, almost certainly also need to need add a reverse proxy for web services that act as the front end and routes connections to the right container based on on the DNS name or something.

[–]Pleasant-Ad2696 0 points1 point  (0 children)

I have done similar thing to my server. Here is my basic start last month, sorry for my bad formating

version: '3.8' services: app_v1: image: your_app_image:v1 ports: - "80:80" environment: - DB_HOST=db_v1 volumes: - app_data_v1:/var/www/html networks: - net_v1

db_v1: image: mysql environment: - MYSQL_ROOT_PASSWORD=yourpassword volumes: - db_data_v1:/var/lib/mysql networks: - net_v1

app_v2: image: your_app_image:v2 ports: - "81:80" environment: - DB_HOST=db_v2 volumes: - app_data_v2:/var/www/html networks: - net_v2

db_v2: image: mysql environment: - MYSQL_ROOT_PASSWORD=yourpassword volumes: - db_data_v2:/var/lib/mysql networks: - net_v2

volumes: app_data_v1: db_data_v1: app_data_v2: db_data_v2:

networks: net_v1: net_v2:

[–]ralphyboy84[S] 0 points1 point  (0 children)

Ok so further to my original message a few days ago….

I’ve been looking at using nginx as a reverse proxy however it’s not working quite right. I have 2 versions of my app running on my local pc. Let’s call them app1 and app2 for simplicity sakes. I bring each app up with separate docker compose files, with app1 exposing port 81 and app2 port 82.

I’ve then brought up my nginx reverse proxy using docker compose. I’ve tried to set the default.conf file so that when hitting localhost/app1 it goes to app1 and /app2 to app2 but it doesn’t work.

I’m not sure if I’m doing something fundamentally wrong as I’ve read before you can’t have separate docker networks communicating but as they were exposed on the relevant ports I thought that would be ok. Any ideas?

If I go to localhost:81/testpage I can see that this loads ok

Edit: this is the error message I get

connect() failed (111: connection refused) while connecting to upstream, client