A few words about Docker
Perform repetitive tasks, are the way to succeed or hit boredom. For example, practice guitar everyday can make you better, don’t learn anything new, boring.
Most of these projects send HTTP requests to the application server for sending push messages. The minimum set up below is required for testing:
- JDK 1.7
- Maven 3.1.1 or superior
- JBoss AS 7 or Wildfly 8.1 Final
- Node.js, npm and bower
- Set the environment variables properly
- Configure SSL certificates
It’s near to impossible to configure everything in less than an hour — Java is tricky sometimes. Minutes later, it starts to get boring. Automation scripts can be helpful, but does not guarantee any portability. This is where Docker comes into play.
The Moby Dock
On OSx, additional steps are required, because Docker engine have specific features tied to the Linux kernel. For this reason, VirtualBox and boot2docker are required. There are two alternatives to install: download from GitHub, which already contains the whole environment required or make use of Homebrew.
On Homebrew, ensure that everything is up to date and the system is ready to brew before getting started:
Next, install boot2docker:
Assuming the installation went well, docker and boot2docker should be available through command line. Now, let’s create a new VM:
The ISO image can be found at $HOME/.boot2docker folder and visualized on VirtualBox
We are all set to start with Docker. As time goes by, the following commands will start become part of routine:
Eventually your VM may run into issues like successively timeouts or aborting, that’s the reason why shellinit so important. It’s responsible for configure DOCKER_HOST and TLS variable (if configured).
For shutting down the image:
To save time, create the following aliases with the basic commands like this:
Eventually upgrade the ISO image is needed for improvements:
Docker Hub and the basics
Most of the official repositories contain images like: Ubuntu, Fedora, Debian and popular application servers easily found at Docker Hub.
Before start, sign up with the GitHub account on Docker Hub. Then attempt to login:
After being prompted for your credentials, you will be able to search for images:
Let’s suppose that something must be tested on Fedora:
Visualize the downloaded images:
Erratum: Is possible to retrive the state of your container, using the ID. Thanks Marc for correcting me. Use commit to save, update and manage the changes into the Docker image.
For testing, run and install some dependencies like Git:
Open a new console to visualize the running containers:
To guarantee that nothing will be lost, persist latest changes:
Build your own image
After play with Docker, is not that hard to realize that’s nearly impossible to memorize all the steps and configuration required to create a custom image. It is recommended to include the instructions in a Dockerfile — the descriptor for building images.
With the base image already there, is possible to extend it on Dockerfile, just providing parameters to FROM:
Our image will have to deal with multiple environment variables to run Java and Node.js, ENV can make it easy. Also, it can also be used on Dockerfile to specify repository names and software versions. Here’s an example:
For command line instructions like
yum install, execution of shell scripts or downloading files RUN is widely used:
By default everything on Dockerfile is executed as root, is strongly encouraged to use non-root credentials instead. Modify the current user quite simple:
Other commands like WORKDIR, EXPOSE and ENTRYPOINT are particularly handy for the boot time definition. For example, copy the project to
/opt/aerogear, expose SSL ports and start WildFly:
Sharing is caring
For automated builds, the documentation has a detailed explanation about it. If you prefer to build the image by yourself, from the directory where Dockerfile is located run:
Check if the image is there:
The interaction with Docker Hub through command line interface is pretty much close to Git. If you are already familiar with it:
The default tag is always
latest, depending on how many changes are done into your image, might be interesting to tag it:
Now with the image available for download everyone can take advantage of it, no matter the experience level with Java. But how to test?
Downloading and exposing the SSL port
Exposing to the private network
For accessing the image, is necessary to discover its IP address:
The host machine (computer with running image) will always have access to Docker containers. But what about other devices?
Consider the following scenario:
- computer, mobile devices: 10.0.1.0/24
- VirtualBox: 192.168.59.0/24
It can be accessible via internal network IP address, if we properly configure the port forwarding:
Now the application server will be accessible to the network.
Docker provides a lot of features for people easily get started with application servers and Linux distros. On AeroGear it helped a lot to put client and server side developers on the same page.
For questions, feel free to contact me. I hope I didn’t bore you too much.