Bluemix creates a group of containers associated with another container

We have a Java application working with MongoDB, each of which is in a different Bluemix container. Both are SINGLE Bluemix containers.

We want to serve the Java application using one of our subdomains: https://subdomain.mydomain.com , which already points to Bluemix. How can we do this?

OUR APPROACH

Since the Java container must reference the Mongo container, we created both containers programmatically (we did not find in the user interface a way to associate the container with another container) as follows:

 sudo bluemix ic run --name mongo-container -p 27017 -m 128 registry.eu-gb.bluemix.net/mycompany/mongo sudo bluemix ic run --name java-container --link mongo-container:mongo -p 8080 -m 128 registry.eu-gb.bluemix.net/mycompany/java 

This works well, but the Java application is only accessible through the ugly Blumix IP, and not through https://subdomain.mydomain.com as we want.

How about using the Bluemix GROUP container ( SCALABLE in the user interface)?

Again, we don’t know how to associate containers with the user interface, so this should be something like

 sudo bluemix ic group-create --auto --name java-scalable -p 8080 -m 128 --hostname subdomain --domain mydomain.com registry.eu-gb.bluemix.net/mycompany/java 

BUT, in accordance with the documentation, we cannot associate a group of containers with a container, since there is no --link .

Return to the original question. How can we serve a Java application using https://subdomain.mydomain.com ?

+5
source share
2 answers

The link parameter basically creates environment variables in one container to access another.

You can do the same with your scalable container on Bluemix.

Here are the steps I took:

1) Create your MongoDB container:

 bx ic run --name ads-mongo -p 27017 -m 128 registry.ng.bluemix.net/namespace/mongo 

2) Check the MongoDB container for a private IP address:

 bx ic inspect ads-mongo 

The private IP address will be at the end of the output, for brevity, I add only part of the output below:

  "Ports": { "27017/tcp": [ { "HostIp": "172.31.0.235", "HostPort": "27017" } ] }, "PublicIpAddress": "" 

3) Launch a scalable container and include one or more environment variables with your MongoDB credentials. Make sure you change the Java code to get the credentials from the environment variables that you pass into the scalable container:

 bx ic group-create --name ads-node -e "MONGO_URI=mongodb://172.31.0.235:27017" -p 3000 -m 128 --hostname ads-node --domain mybluemix.net registry.ng.bluemix.net/namespace/ads-nodebx 

In my test, I used the Node.js application and read the MONGO_URI environment MONGO_URI for MongoDB credentials.

You can assign a public IP address for your MongoDB container, if you want, the end result should be similar. The only difference that I see is that you can access your db using the mongo command line or other tools to connect to the database.

+2
source

So, following the second approach, you can create the MongoDB service before creating the Bluemix container group. When creating a Bluemix container group, you have the option of linking an existing service in the Advanced Settings section of the user interface:

enter image description here

You can also use a custom domain during the creation of the Container if you have already created it:

enter image description here

In this case, you will have a container with a custom domain, which also includes the existing service.

For more information on binding an existing service, see the Container Integration Documentation . For more information on creating a custom domain in Bluemix, see Updating application documentation .

+2
source

Source: https://habr.com/ru/post/1268055/


All Articles