Two instances of same application with docker-compose

Hi All,

I am currently running docker-compose version 1.18.0, build 8dd22a9

I have an application TEST (Version 1) which is running on a Linux server. When I need to start the application I use “docker-compose up -d” command. I have docker-compose.yml that lists nginx and tomcat(connects to external DB) on port 80:80, 443:443

I want to have another instance of application TEST but Version 2, I want TEST-version1 and TEST-version2 to run simultaneously from the same server on a different port so users can access both. How can I do that with docker-compose ?

Thank you

Instead of hard-coding the ports you could set environment variables in a .env file and use them in the compose file. Read Variable substitution in the docs.

This thread might discuss the same problem and might provide an approach to solve your problem:

Use fixed ports for the production environment and use dynamic ports for the other environment files. Use docker-compose port to find out the dynamic ports.

$ docker-compose port
Print the public port for a port binding.

Usage: port [options] SERVICE PRIVATE_PORT

Options:
    --protocol=proto  tcp or udp [default: tcp]
    --index=index     index of the container if there are multiple
                      instances of a service [default: 1]