Docker for Developers - How To Use Docker for Development?
It is always an experience to use Docker for development. Generally, It’s not much different than the normal way to do development work through Docker. Developer should keep only two things in consideration in dealing with Docker.
1. All the dependencies should be there in the working directory including code.
2. One needs to change the build and he should go on with the commands to run inside a Docker container.
Let us examine the process below with at least two setups with different languages.
Docker to run Ruby applications
Here is the example of Hello World operating in Ruby. It does not need to install Ruby to run this.
At first Developer should copy the required code and then to put it in a file called hello.rb.
Now it is ready for a run .
"Hello Ruby!" is almost a universally usable command that one use for almost everything and everywhere . Next step is followed by an addition of a dependency . It does not need to install the dependencies into the container.
Then the user copies this into Gemfile:
Again hello.rb needs a change to be hello-world.
If bundle install is used to install the gems, there ruby hello.rb is also operable. But it will be unable to run inside the Docker container, since iron_mq gem is not there inside the container. The installation of this inside the container may have a certain uncontrollable ramifications . Ephemeral containers are always desirable. Developer is always ensconced in vendoring his dependencies and loves to keep all code and dependencies together in a nice little package.
After installing the dependencies into the working directory , if there is a need to compile native extensions that can be done on the right architecture.
It needs one more change to use the new bundle hello.rb. One can notice a "require_relative" line at the top. Developer now run it again with its new dependency. This is how the things happen.
One can run it on a different version of Ruby, like Ruby 1.9. Only it seeks for a different container.
Web apps
The first step to make a web app is to open ports. The developer just delivers the -p PORT:PORT flag to docker run.
Now it is time to copy the code into webapp.rb.
Here needs an addition of gem 'sinatra' to the Gemfile. It is now all set for a run with bundle install command again. It leads to run a new integrated command. Therefore, the Developer is now prepared for a check of the whole work at http://localhost:8080.
Conclusion
From the above two work flows of two different apps processed through Docker it is clear that most of these things are common so far the application is concerned in both the narrative , with some minor differences. It also evident that it doesn't change the development process too much and it can offer many benefits during the development pathway. It follows almost a common road with some minor differences while developing the apps in other languages as well. Developers love Docker for its ease of doing business.
Visit our following sections of Docker tutorial: