In this post, you will learn how to create and push a Docker container to Bluemix via the Bluemix CLI. This post includes:
- Steps to set up and use the Bluemix CLI.
- Creating and running your container on IBM Bluemix.
I have been exploring and playing with containers, more specifically Docker containers, for a while now, and I've been doing the same with IBM Cloud. But I just thought about exploring both worlds together. Then there came the option to create a container on Bluemix.
Setting Up bx CLI
The Bluemix CLI is supported on all major operating systems. Just to keep the blog post compact and simple, I will be running all the commands on macOS terminal.
- Bluemix Account – Signup / Login
- Docker CLI
- Before installing the Bluemix CLI, install Cloud Foundry's CLI
- Download the Bluemix CLI from here
Now, let's run through commands. For starters, here's the command to check whether Bluemix (bx) CLI is installed:
And to check the version of your installation:
And finally, to update your Bluemix CLI, run the command:
Like Cloud Foundry's CLI, the Bluemix CLI supports a plugin extension framework to integrate other commands besides the built-in ones.
- To install Bluemix CLI plug-ins from the Bluemix registry, set the plug-in registry endpoint:
bx plugin repo-add bluemix-bx https://plugins.ng.bluemix.net
- Then, run the following command to install a IBM Container (ic) plugin:
bx plugin install IBM-Containers -r Bluemix-bx
Replace IBM-Containers with any plugin-name you want to install
To update a plugin, run the below command
bx plugin update <plugin-name> -r Bluemix-bx
To confirm that you are good to create a container via Bluemix CLI, run the below command
bx ic --help
Note: bx stands for Bluemix and ic stands for IBM Containers.
You should see all the IBM container commands.
Creating Your First Container on Bluemix
Before creating your container on Bluemix, you should log in with the command:
$ bx login -a https://api.ng.bluemix.net API endpoint: https://api.ng.bluemix.net Email> firstname.lastname@example.org Password> Authenticating... OK
Let’s generate client certificates for IBM Containers to initialize the container environment on your local machine. Then, we can use the full capabilities of the IBM Containers service. Run the command:
bx ic init
Set the name of the private Bluemix image repository the organization that you are logged into.
Restriction: You can’t use a hyphen
- in the name of your repository namespace.
bx ic namespace-set <namespace-name>
Now, the path to any image under your private registry will be:
To read your namespace anytime, run the command:
bx ic namespace-get
To check the images, run the command:
bx ic images
Using the below command you can move an image from public registry like DockerHub to your private registry on Bluemix
bx ic cpi hello-world registry.ng.bluemix.net/<namespace-name>/hello-world
By running the above command you are copying hello-world image to your private registry under your own namespace.
Let’s run our container on Bluemix:
bx ic run -it registry.ng.bluemix.net/<namespace-name>/hello-world
Hello from Docker. This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker Hub account: https://hub.docker.com For more examples and ideas, visit: https://docs.docker.com/userguide/
Run this command to see all the containers under your private registry on Bluemix:
bx ic ps -a.
You can run
docker COMMAND –help for more information on Docker commands. Meanwhile, using
bx ic help will do the same for for IBM Containers commands.
export BLUEMIX_TRACE=true or
bluemix ic COMMAND -v|–verbose to enable debug mode.
[COMMAND OPTIONS] [ARGUMENTS…]
In subsequent articles, you will see how to containerize an existing Node.js app (GitHub repo) by drafting a Dockerfile. Then, we'll run it on Bluemix. That will be followed by an introduction to the new IBM Container service and its CLI commands.