Development environment – It can take too long to set it up
Have you ever thought that how long does it take for an entry level developer to setup a new project development environment? The answer depends on many factors like the project age, the number of developers worked on it etc. but don’t get surprised if you get answer half a day or more.
Hey! It should be much faster than that: checkout a script and execute it. That’s all. Two steps should be sufficient to setup your environment and get ready for development.
Deployment environment – It can differ too much from testing and production environments
Have you ever skipped your build’s automated tests because they failed on your machine? Or even worst, have you ever been the cause of a build break even if your changes compiled smoothly on your machine but failed consistently on CI server?
Any slight difference can result in an unexpected behavior. Diverging can be as simple as giving a try to the last version of a framework or switching to a different project for half a day.
Finding out what makes your system behave differently is an annoying task every developer should avoid.
Welcome to the docker world!!!
What is Boot2Docker?
Boot2Docker is a lightweight Linux distribution based on Tiny Core Linux made specifically to run Docker containers. It runs completely from RAM, weighs ~27MB and boots in ~5s.
Why should we use Boot2Docker:
The Boot2Docker project smoothens the gap by bringing Docker to an otherwise incompatible platform. If you want to prepare a packageable and easily shippable program from a windows/mac environment you should use this. It allows you to run Linux containers through windows/mac.
To make this process easier, docker has designed a helper application called Boot2Docker that installs the virtual machine and runs the Docker daemon.
How would we do that?
Setup Boot2Docker on windows to run a tomcat instance:
- Download docker-install.exe from https://github.com/boot2docker/windows-installer/releases.
- Run the installer, which will install VirtualBox, MSYS-git, the boot2docker Linux ISO, and the Boot2Docker management tool.
- Go to GitBash from Windows start.
- Run the command Boot2docker up. This will bring up a LINUX VM into which we will ssh in the next step. Docker daemon would eventually be running on this VM.
- Run the below command to ssh into the VM “c:\Program Files\Boot2Docker for Windows\boot2docker.exe” ssh -L 8080:localhost:8080. This also specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.
- Let’s run a tomcat server. This will download the server image if not already present and bring it up. docker run -it –rm -p 8080:8080 tomcat:8.0. The server will run to be accessible on port 8080 from the host.
- Try yourself hit http://localhost:8080.
Deploy a war to tomcat:
- Download winscp from http://winscp.net/download/winscp556setup.exe
- Open GitBash window from windows start
- Obtain the ip address of the boot2docker VM using boot2docker ip. Default ip is 192.168.59.103
- Login to the VM using the default credentials.
- The default user is docker and the password is tcuser.
- FTP cloud.war(any war file) to base location on docker VM.
- To copy the war to the webapps folder and run the tomcat image use the following command: docker run -it -d –name tomcat -v $HOME/cloud.war:/usr/local/tomcat/webapps/cloud.war:ro -p 8080:8080 tomcat:8.0
Publish an image to a private repo:
We will be using quay.io for our private repo hosting. All the docker images your team needs can be uploaded here, to be pulled on later. You will have to sign in. Use the link https://quay.io/signin/
In order to publish the image, follow the steps below:
- The following command gets the list of containers running on the VM: docker ps. Copy the container id from here. For me it was: 910ea9ae38fe
- The following command gets the list of images running on the VM: docker images. Copy the image id. For me it was b5e4c1b6e097
- From the VM login to quay using : docker login quay.io
- Commit the image using the command: docker commit containerid imageid docker commit 910ea9ae38fe b5e4c1b6e097
- We next need to tag the container to a known image name docker tag image id quay.io/abhinav446/demo
- Finally lets push our image docker push quay.io/abhinav446/demo
- Pull this image id anywhere and do a run as we did before.