Try to start multiple container instances with override files

Hi,
I have a docker-compose file that defines two images. I use the override technique to define customer specific settings, for example a binding to the host file system. Starting and overriding works fine. The containers that are named with the customer name, I all it “customerA” are running. That is cool.
Well, I want parallel to start another container for another customer. To achive this I defined another docker-compose-override files. If I start the containers for “customer B”, the containers from “customer A” are stopped and the container for “customer B” is started instead.
I want that the containers for both customers are running parallel.
I override the container names and the network names.
What do I have to else, that the containers for both customers are running parallel?
Thanks,
Christian

What you experience is the default behavior of docker-compose. If no project name is provided, the directory name is used. In your situation each customer will need it’s own project name. Though, bare in mind that the --project-name option needs to be used on every docker-compose command then…

  -p, --project-name NAME     Specify an alternate project name
                              (default: directory name)

source: https://docs.docker.com/compose/reference/overview/

Hi Metin,
thanks a lot for yours help. I am one step further.
Now I have the next problem. All the containers access a SQL Server on the host. I have a Port-Binding configured. I can start the container for the first customer. Starting the container for the second customer ends in a exception, that the port is already in use from the first container.
Do you know how to solve this problem?
Thanks,
Christian

Please share your docker-compose.yml’s. Please do not redact anything except external domain names, usernames and passwords. My experience is that people tend to redact away the problems because they think it’s unrelated…

I am not realy a fan of “lets solve the problem of the minute and carry on to the next. Rinse and repeat until everything works.” without having a chance to see the big picture.

Hi Metin,

thanks for yours help.
This is the “base” docker-compose file:

version: ‘3.6’
services:

my_solr:
container_name: mySolr
volumes:
- type: bind
# source: The path with the customer specific (‘HuberGmbH’) subdirectory on the host computer
source: “/E:/Mandaten/HuberGmbH/Solr”
# target: The path in the Docker container
target: “/opt/solr/server/solr/mycores/MyCore”
image: solr:7.7.2
entrypoint:

  • bash
  • “-c”
  • “precreate-core MyCore; exec solr -f”

my_server:
container_name: myServer
environment:
mysettings: "{“Settings”:{“Server”:{“Port”:“9898”,“MobilePort”:“8888”,“DoStartMobileServer”:“true”},“Database”:{“Name”:“myName”,“ServerName”:“docker.for.win.localhost\\SQLEXPRESS2017”,“DatabaseName”:“myDatabaseName”,“DatabasePort”:“49172”,“DatabaseType”:“Microsoft_SQL_Server”,“IsAzure”:“false”,“UserName”:“munixouser”,“Password”:“Blabla!#”,“ReadUserName”:“myuser”,“ReadUserPassword”:“Blabla!#”,“ExistsSolrServer”:“true”,“SolrServerHost”:"http://mySolr:8983/solr/myCore",“CommandTimeOut”:“30”,“PathForDocuments”:"/usr/novi",“DefaultAuthorizationSetting”:“deny”}}}"
build: ./ #builds the image as defined in “Dockerfile”
depends_on:

  • my_solr # Inform docker to create a “solr” container first
    volumes:
  • type: bind
    source: “/E:/Mandaten/HuberGmbH/System”
    target: “/usr/novimnt”

This is the first override docker-compose override file:

version: ‘3.6’
services:
my_solr:
container_name: mySolrSample
volumes:
- type: bind
source: “/E:/Mandaten/sample/Solr”
target: “/opt/solr/server/solr/mycores/myCore”
ports: # must be defined in this override file

my_server:
container_name: myServerSample
environment:
myserversettings: "{“Settings”:{“Server”:{“Port”:“9898”,“MobilePort”:“8888”,“DoStartMobileServer”:“true”},“Database”:{“Name”:“Emasos”,“ServerName”:“docker.for.win.localhost\\SQLEXPRESS2017”,“DatabaseName”:“mxo_Novicon_Ref1”,“DatabasePort”:“49172”,“DatabaseType”:“Microsoft_SQL_Server”,“IsAzure”:“false”,“UserName”:“myuser”,“Password”:“Lala!#”,“ReadUserName”:“myuser”,“ReadUserPassword”:“Lala!#”,“ExistsSolrServer”:“true”,“SolrServerHost”:"http://mySolrSample:8983/solr/myCore",“CommandTimeOut”:“30”,“PathForDocuments”:"/usr/nuui",“DefaultAuthorizationSetting”:“deny”}}}"
ports:
#[HOST-PORT] : [CONTAINER-PORT]

  • “49172:49172” #SQL Server port
  • “9898:9898” #my Client to my Server
    networks:
  • app-net-sample
    volumes:
    - type: bind
    source: “/E:/Mandaten/sample/myServer”
    target: “/usr/novimnt”

networks:
app-net-sample:

This is the second docker-compose override file:

version: ‘3.6’
services:
my_solr:
container_name: mySolrSample2
volumes:
- type: bind
source: “/E:/Mandaten/sample2/Solr”
target: “/opt/solr/server/solr/mycores/myCore”
ports:

my_server:
container_name: myServerSample2
environment:
myserversettings: "{“Settings”:{“Server”:{“Port”:“9899”,“MobilePort”:“8888”,“DoStartMobileServer”:“true”},“Database”:{“Name”:“Emasos”,“ServerName”:“docker.for.win.localhost\\SQLEXPRESS2017”,“DatabaseName”:“mxo_Novicon_Ref1”,“DatabasePort”:“49173”,“DatabaseType”:“Microsoft_SQL_Server”,“IsAzure”:“false”,“UserName”:“myuser”,“Password”:“Lulu!#”,“ReadUserName”:“myuser”,“ReadUserPassword”:“Lulu!#”,“ExistsSolrServer”:“true”,“SolrServerHost”:"http://mySolrSample2:8983/solr/myCore",“CommandTimeOut”:“30”,“PathForDocuments”:"/usr/novi",“DefaultAuthorizationSetting”:“deny”}}}"
ports:

  • “49172:49173” #SQL Server port
  • “9899:9899” #my Client to my Server
    networks:
  • app-net-sample2
    volumes:
    - type: bind
    source: “/E:/Mandaten/sample2/my”
    target: “/usr/novimnt”

networks:
app-net-sample2:

Regards,
Christian

Could you do me favor and repost it and use the </> button to past it as preformated text this time? It makes it way easier to read. Hint: leave an emtpy line before your compose.yml, mark everything and klick the button. This way it will keep the indention.

Hi Metin,

of couse. I did not know “Preformatted text” option. Thanks for that hint and for yours engagement.

The “Master” Docker-Compose file:

version: '3.6'
services:

 my_solr:
  container_name: mySolr
  volumes:
    - type: bind
      # source: The path with the customer specific ('HuberGmbH') subdirectory on the host computer
      source: "/E:/Mandaten/HuberGmbH/Solr" 
      # target: The path in the Docker container
      target: "/opt/solr/server/solr/mycores/MyCore"
  image: solr:7.7.2
  entrypoint:
   - bash
   - "-c"
   - "precreate-core MyCore; exec solr -f"
 
 my_server:
  container_name: myServer
  environment:
   mysettings: "{\"Settings\":{\"Server\":{\"Port\":\"9898\",\"MobilePort\":\"8888\",\"DoStartMobileServer\":\"true\"},\"Database\":{\"Name\":\"Emasos\",\"ServerName\":\"docker.for.win.localhost\\\\SQLEXPRESS2017\",\"DatabaseName\":\"myDatabaseName\",\"DatabasePort\":\"49172\",\"DatabaseType\":\"Microsoft_SQL_Server\",\"IsAzure\":\"false\",\"UserName\":\"munixouser\",\"Password\":\"Blabla!#\",\"ReadUserName\":\"myuser\",\"ReadUserPassword\":\"Blabla!#\",\"ExistsSolrServer\":\"true\",\"SolrServerHost\":\"http://mySolr:8983/solr/myCore\",\"CommandTimeOut\":\"30\",\"PathForDocuments\":\"/usr/novi\",\"DefaultAuthorizationSetting\":\"deny\"}}}"
  build: ./ #builds the munixo image as defined in "Dockerfile"
  depends_on:
   - my_solr # Inform docker to create a "solr" container first
  volumes:
   - type: bind  
     # source: The path with the customer specific ('HuberGmbH') subdirectory on the host computer
     source: "/E:/Mandaten/HuberGmbH/System"
     # target: The path in the Docker container
     target: "/usr/novimnt"  
#networks:
# app-net:

The override file from the first customer:

version: '3.6'
services:
 my_solr:
  container_name: mySolrSample
  volumes:
    - type: bind
      source: "/E:/Mandaten/sample/Solr"
      target: "/opt/solr/server/solr/mycores/myCore"
  ports: # must be defined in this override file
   - "8983:8983" # to invoke the Solr admin console http://localhost:8983/ 
  networks:
   - app-net-sample

 my_server:
  container_name: myServerSample
  environment:
   myserversettings: "{\"Settings\":{\"Server\":{\"Port\":\"9898\",\"MobilePort\":\"8888\",\"DoStartMobileServer\":\"true\"},\"Database\":{\"Name\":\"myName\",\"ServerName\":\"docker.for.win.localhost\\\\SQLEXPRESS2017\",\"DatabaseName\":\"mxo_Ref2\",\"DatabasePort\":\"49172\",\"DatabaseType\":\"Microsoft_SQL_Server\",\"IsAzure\":\"false\",\"UserName\":\"myuser\",\"Password\":\"Lala!#\",\"ReadUserName\":\"myuser\",\"ReadUserPassword\":\"Lala!#\",\"ExistsSolrServer\":\"true\",\"SolrServerHost\":\"http://mySolrSample:8983/solr/myCore\",\"CommandTimeOut\":\"30\",\"PathForDocuments\":\"/usr/nuui\",\"DefaultAuthorizationSetting\":\"deny\"}}}"
  ports:
    #[HOST-PORT] : [CONTAINER-PORT]  
   - "49172:49172" #SQL Server port
   - "9898:9898" #my Client to my Server
  networks:
   - app-net-sample
  volumes:
    - type: bind  
      source: "/E:/Mandaten/sample/myServer"
      target: "/usr/novimnt"  
    
networks: 
  app-net-sample:    

And the override file from the second customer:

version: '3.6'
services:
 my_solr:
  container_name: mySolrSample2
  volumes:
    - type: bind
      source: "/E:/Mandaten/sample2/Solr"
      target: "/opt/solr/server/solr/mycores/myCore"
  ports:
    #[HOST-PORT] : [CONTAINER-PORT]
   - "8984:8984" # to invoke the Solr admin console http://localhost:8983/ 
  networks:
   - app-net-sample2

 my_server:
  container_name: myServerSample2
  environment:
   myserversettings: "{\"Settings\":{\"Server\":{\"Port\":\"9899\",\"MobilePort\":\"8888\",\"DoStartMobileServer\":\"true\"},\"Database\":{\"Name\":\"myName\",\"ServerName\":\"docker.for.win.localhost\\\\SQLEXPRESS2017\",\"DatabaseName\":\"mxo_Ref1\",\"DatabasePort\":\"49173\",\"DatabaseType\":\"Microsoft_SQL_Server\",\"IsAzure\":\"false\",\"UserName\":\"myuser\",\"Password\":\"Lulu!#\",\"ReadUserName\":\"myuser\",\"ReadUserPassword\":\"Lulu!#\",\"ExistsSolrServer\":\"true\",\"SolrServerHost\":\"http://mySolrSample2:8983/solr/myCore\",\"CommandTimeOut\":\"30\",\"PathForDocuments\":\"/usr/novi\",\"DefaultAuthorizationSetting\":\"deny\"}}}"
  ports:
  #[HOST-PORT] : [CONTAINER-PORT]    
  - "49172:49173" #SQL Server port 
  - "9899:9899" #my Client to my Server
  networks:
   - app-net-sample2
  volumes:
    - type: bind  
      source: "/E:/Mandaten/sample2/my"
      target: "/usr/novimnt"  
    
networks: 
  app-net-sample2:

The port collision of your pubished port is due to:
- "49172:49172" #SQL Server port
and
- "49172:49173" #SQL Server port

The left hand side of the mapping is the host port, which must be unique, the right hand side is the container port, which is private to the container and can be identical in all instances.

Observations:
– In your json string, the configuration for Servername clearly points to a rdbms on your host (docker.for.win.localhost\\SQLEXPRESS2017). Published port are used to forward a host port to a container port - for ingress operations. Egress operations do not require publised ports. Do you realy need aboves published ports?
– there is no need to use different container names and network names for different projects. Internaly they can be the same, externaly docker compose will prefix them with the project name. They will not be in the same bridged network and won’t be able to access a container of the other projects (does that make sense?)

1 Like

Hi Metin,
thank you very much, I am thrilled :upside_down_face:
Now I can start the containers for both customers. Very, very cool :+1:
And yes, yours explanation are very, very good.
Today I can sleep well.

Best regards,
Christian

1 Like