Deploy IPython Notebooks With Docker On Bluemix In Minutes
JeanFrancoisPuget 2700028FGP Comments (2) Visits (28853)
Are you interested in deploying Docker containers in IBM Bluemix? Are you developing these containers on a Windows workstation with Boot2Docker? If you answered yes to both then this post is of interest. Furthermore, if you are using IPython notebooks then this post is definitely worth a read!
The Docker container service on IBM Bluemix is IBM Containers . This service is currently in beta test and I was lucky enough to get access to it. You can register for the beta on Bluemix home page shown above.
In order to use this service we must first install IBM Containers Extension (ice) on our local Docker host. We provided detailed instructions for installing it here. We therefore assume that you have a working installation of Boot2Docker with ice.
The first step is to log into ice. Just type ice login and follow instructions. You must use the credentials you used when registering to the service.
All the erased parts in the above screenshot are my email. I entered once, and it is used as my user ID and my org ID. You should see yours instead when you log in.
We are now all set. Let's move to IBM Containers a container we created in a previous post. Let's move the Docker image we created first. That image was created with a Dockerfile in the myserver directory. We can reuse ithe same dockerfile with ice. The content of the dockerfile is
Our image is derived from the ipython/scipyserver image. In order to save you time I recommend that you copy the ipython/scipyserver image directly from Docker Hub to IBM containers before building the image. If you don't then it will be uploaded from your local machine, which may be quite slower. The command for that is:
ice cpi ipython/scipyserver <your ice repo
For me it is
ice cpi ipython/scipyserver jfpu
Once completed, check that the image is available with ice images:
We see the two base images of the service (ibmnode and ibmliberty), plus two images I copied from Docker Hub (anaconda and scipyserver)
We can now build our new image. The ice command is very similar to the docker one:
ice build -t jfpuget/myserver .
Note the ending dot: it tells where the DockerFile is. We specify our image name with the -t option. We need to give our ice repository name, here jfpuget, and an image name, here myserver.
We see that it skips some steps thanks to the previous upload of the ipython/scipyserver image. If we hadn't done that then we would be waiting for the upload of about 2.5 GB from our local machine to IBM Bluemix. It sure can take some time!*
Once the build it complete we can check that the image is available on the service with ice images
We can now create a container with it. The command is similar to the Docker command. The docker command was
docker run -d -p 443:8888 -p 9000:9000 -e "PA
We obviously cannot mount a local host directory into a container running on the cloud. We therefore need to create a Docker volume on the cloud. The ice command for that is very simple:
ice volume create notebooks
We simply provide a name for the volume. Once created we can check that the volume exists with ice volume list:
We also need to provide an ip address. We first request a public IP address. The command is
ice ip request
Once executed we get an ip address. Beware, for the beta version we can only get 2 public ip addresses. We can list the ones we already have with ice ip list
We will then bind this address to our container once it is created.
We are all set. The ice command is very similar to the Docker command.
ice run --memory 1024 -p 8888 -p 9000 -e "PAS
Beside the difference in the volume we mount and the ip address, there is a difference in the way we expose ports. Docker enables port mapping. With ice we cannot map an internal container port to a different external port.
Executing the command should build the container for us, then deploy it on our Bluemix repository. Indeed, we see our container up and running on the Bluemix dashboard:
We now bind the ip address to it with ice ip bin
Let's go back to the Bluemix dashboard. We now see the public ip address for our container
Let's see if it is working correctly. This container is the same as the one we created in Using IPython Notebooks In Docker Containers On Windows. It should run an IPython notebook server and persist notebooks in the notebooks volume we mounted. The notebook should e accessible on port 8888 of the container, hence should be accessible at http
Entering this address in a web browser opens a page that asks a password. After a security warning because we haven't used a known certificate, we get to the home page where a password is required.
Jupyter is the new name for IPython notebook server. Without surprise, the required password is the one passed as argument to the docker run command. If you haven't modified it is should be MakeAPassword. I do hope you've modified it though...
After entering the password we get to the notebook server.
There is no notebook as we started a brand new server but you can start using it.
You should get this view
Once downloaded the notebook can be uploaded onto the server via its upload button.
Clicking the notebook starts its Python kernel, and opens a new window (or a new tab depending on your browser configuration) that displays the notebook content.
We run it all via Cell → Run All
This notebook launches a Sudoku web app on port 9000. To access it we enter http
Seems the app is up and running. We test it by clicking the solve button. It displays the result after solving the grid via our DOcloud service.
Note that our web app code didn't require any modification to run on Bluemix. This is because we used the same Docker container on Bluemix than on our development machine. This is remarkable as our development machine is a Windows workstation when Bluemix runs Linux VMs.
Let's recap the architecture we are running. We run our Sudoku web app in a Python notebook. The notebook runs in a Docker container. The container is run inside the IBM containers service on IBM Bluemix.
We tested this architecture using Docker on a Windows workstation. The architecture there was
Docker insulates us from the underlying host, whether it is Windows or Bluemix. Using it is also simpler than the methods described in these two interesting posts by Peter Parente
A final word: I stopped the python kernel of the notebook. Therefore the web app is no longer available. But you can easily build it for yourself using the above instructions.