hosting core in a bluemix container

so in the last few posts we created a .net core console app then dockerized it and then we created an core app and ran it.

we're gonna now pull this together and take our core app and run it in IBM Bluemix and host it as a docker container.

So all we need to is add a Dockerfile to our application


FROM microsoft/dotnet:latest  
COPY . /app  

RUN ["dotnet", "restore"]  
RUN ["dotnet", "build"]


ENTRYPOINT ["dotnet", "run"]
Key points

1) In our previous app, we were hosting our app on port 8080 hence why we're exposing that..

2) IBM Containers support use of docker images, so we're just using the microsoft/dotnet:latest image directly

Login into Bluemix

Bluemix is IBM's cloud platform, it's pretty good and has a decent free offering as well, so if you want to host some containers etc, not a bad place to do it.

Once you've got yourself an account, you just need to log into the container service.

cf ic login  

it will then prompt you for your email address and password.
Once logged in then you can build your image directly in bluemix..

Build your image in bluemix

cf ic build -t registry.<region><namespace>/<imagetag> .  

Note: if depending on your region, namespace etc and what you want to name your app, you will need to set the values appropriate. The example below shows that my image is called helloaspnet, i'm hosted in eu-gb and my namespace is ixplayground.

cf ic build -t .  

Bluemix will then build the app...
And you can see your images using the following command

cf ic images  

which results in

christopherhay$ cf ic images  
REPOSITORY                                            TAG                   IMAGE ID            CREATED             SIZE   latest  

Request an IP Address

So my container is gonna need a public ip address, so that we can hit our website, so i need to request that

cf ic ip request  

and i can see what ip addresses, i have assigned with

cf ic ip list  

for example

christopherhay$ cf ic ip list  
Number of allocated public IP addresses: 1

Listing the IP addresses in this space...  
IP Address       Container ID   b8b43ac2-f647-4fef-84c4-0459abc87b6d  

Run my container in bluemix

Now i have my container and IP address, i want to run my container. In this example we will directly bind the IP address to the container but in production scenarios (or for efficiency with ip addresses) you will want to front-load this with a proxy / load balancer such as nginx.. we will ignore that for now.

so, it's time to run my service

cf ic run -p  

And it will return me the container id

ChristophersMBP:helloaspnet christopherhay$ cf ic run -p  

And i can now hit my core website running in my container in bluemix.

Listing and killing containers

If I want to see what containers i'm running, you can just perform cf ic ps

christopherhay$ cf ic ps  
CONTAINER ID        IMAGE                                                        COMMAND             CREATED             STATUS                  PORTS                           NAMES  
75daf09e-220   ""                  2 minutes ago       Running 2 minutes ago>8080/tcp   prickly_morse  

And if you want to kill the container

christopherhay$ cf ic kill 75daf09e-220  

75daf09e-220 is the short version of the containerid.

DONE, you have now have an core docker container running in IBM Bluemix on Ubuntu.. Pretty cool huh

chris hay

Read more posts by this author.