More playing with Docker. Now, where can I deploy a container ‘for real’ to the cloud? A few options:
- AWS has EC2 Container Service (ECS). If you haven’t used AWS before you can get a year of AWS for free. If you’ve already used up your free year, then it looks like you’ll have to pay as you go for ECS
- Google Container Engine have a $300 free offer for 60 days
- Digital Ocean – $5/month on lowest spec plan
- Heroku has Docker support using a Docker image of their own runtime platform, Heroku Cedar. This is an interesting approach, but sounds more attractive if you’re already planning on deploying to Heroku as your target platform
- OpenShift Origin v3 is Docker based, but only if you’re running OpenShift Origin yourself. OpenShift Online is still their own proprietary gears and cartridges (although still an awesome PaaS that I use for a lot of my side-projects – this blog is hosted on OpenShift).
So where does IBM’s Bluemix fit in to this picture? I have to admit, until seeing IBM’s presentations at JavaOne this year about how awesome their cloud service is, I hadn’t even taken a look at what they have to offer (I think years of devolping and deploying to Websphere v5 had left me emotionally scarred). Bluemix is Cloud Foundry based, with tons of other stuff thrown in. Including support for hosting Docker containers. And, free developer accounts (when CPU and stoarage kept below a certain level) – check out the pricing calculator. Ok, so I’m in, let’s get set up.
Deployment is via the CloudFoundry CLI with the IBM Containers plugin, instructions are here. Here’s a summary:
- Installer Docker if not already installed
- Install CloudFoundry CLI
- Install IBM Containers cf plugin
- Login to Bluemix: cf login -a api.ng.bluemix.net
- Login in IBM Containers: cf ic login (login with Bluemix credentials when prompted)
There’s a couple of options to interact with your containers and walking through the docs the first time it’s a little confusing as they list all three alternatives for each step – either with docker cli directly, with cf cli or with the ice cli.
From the Bluemix containers dashboard, when you click add custom container, the steps it gives you are using cf cli to login, and then use the Docker cli, so this is the approach I used (the ice cli seems to give me 503 Bd Gateway errors that I couldn’t get beyond, so I followed the cf and Docker steps).
I already have my image running a JAX-RS endpoint using WildFly Swarm – let’s get it deployed to Bluemix.
I already have my image, built with:
docker build -t wildflyswarm-jaxrs
Next, we need to tag it:
docker tag wildflyswarm-jaxrs registry.ng.bluemix.net/kevinhooke/wildflyswarm-jaxrs
- the first param is the tag name from when we built the image
- second param is the Bluemix image repository uri, followed by your account namespace (set when you register with Bluemix), and then the tagname for your image
docker push registry.ng.bluemix.net/kevinhooke/wildflyswarm-jaxrs
At this point if you head over to your Bluemix Containers dahboard, you’ll see your image listed (along with some provided images from IBM):
Using the cf cli with the IBM Containers plugin, ic), you can issue docker comands direct to Bluemix, so to list containers remotely:
cf ic images
Let’s start a container from the image!
cf ic run --name jaxrs-test registry.ng.bluemix.net/kevinhooke/wildflyswarm-jaxrs
This should return you a container id.
So is it running? Let’s pass a Docker ps using cf ic:
cf ic ps
We’re up and running! (or at least building, it hasn’t started yet)
Now how do we access the service in the container? It seems like we need to go to the online console and request a public IP for the container. The free account gives you 2 free public IPs:
From the cli, the approach is to request a public ip:
cf ic ip request
and note the returned ip.
Now start the container and pass the ip from the previous step – I’m also binding 8080 from my container to 8080 on the host to make it accessible:
cf ic run -p 184.108.40.206:8080:8080 --name jaxrs-test registry.ng.bluemix.net/kevinhooke/wildflyswarm-jaxrs
The docs say the public ip may take a few minutes before it’s available.
I don’t know how long the containers in Bluemix normally take before they transition to running, for me it seemed to take a while in the ‘networking’ status.
After waiting a few minutes and checking the console, SUCCESS, we’ve transitioned to ‘running’:
And pointing a browser at the public ip and port, the app is up and running! JAX-RS using WildFly Swarm, in a Docker container, deployed to IBM Bluemix!