we're gonna now pull this together and take our asp.net 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 asp.net application
FROM microsoft/dotnet:latest COPY . /app WORKDIR /app RUN ["dotnet", "restore"] RUN ["dotnet", "build"] EXPOSE 8080 ENTRYPOINT ["dotnet", "run"]
1) In our previous asp.net 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>.bluemix.net/<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 registry.eu-gb.bluemix.net/ixplayground/helloaspnet .
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 registry.eu-gb.bluemix.net/ixplayground/helloaspnet 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
christopherhay$ cf ic ip list Number of allocated public IP addresses: 1 Listing the IP addresses in this space... IP Address Container ID 188.8.131.52 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 184.108.40.206:8080:8080 registry.eu-gb.bluemix.net/ixplayground/helloaspnet
And it will return me the container id
ChristophersMBP:helloaspnet christopherhay$ cf ic run -p 220.127.116.11:8080:8080 registry.eu-gb.bluemix.net/ixplayground/helloaspnet 75daf09e-220b-49fe-bf63-84ac9f290780
And i can now hit my asp.net 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 registry.eu-gb.bluemix.net/ixplayground/helloaspnet:latest "" 2 minutes ago Running 2 minutes ago 18.104.22.168:8080->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 asp.net core docker container running in IBM Bluemix on Ubuntu.. Pretty cool huh