Pages

Customizing docker image | case example

Using concourse for ci-cd pipelines.
Concourse internally uses docker images for its jobs.
Jobs basically require some input and output folders and some environment variables to be set, and then the commands to be executed.

Basically docker container is like an instance of virtual machine with the required environments configured so that user can directly use the binaries to execute commands and do the job.
For example, to run a npm command in the docker, you require a docker image with npm binaries already installed and configured. So when you start the container, you can just start executing those commands.

Sometimes, you will not find a docker image with all the dependencies installed and configured into it. So you will have to prepare the environment yourself once.
I encountered a similar situation where most of the things were configured in one of the docker image but some of the additional dependencies which i require were not there.
I did some research and got the work done.

Basically I had to build some old tomcat grid applications in the pipeline and publish the results to quality hub.

I found a docker image with the java, and ant configured but ivy binaries were missing in the image.

NOTE: IVY is the dependency management api which is normally used in Ant projects. Its similar to maven in that you declare dependencies in an xml file and it can download that for you.

So, here are the steps to get the work done.
1. Pull and run the first docker image.

docker pull docker.artifactory.rajan.com/java/ant-image:latest
docker run -itd --name ant-ivy docker.artifactory.rajan.com/java/ant-image sh

Note: if your docker image is in custom artifactory and not in docker hub, you have to give the complete path of the artifactory as shown above.

2. Attach your cmd to the docker container and check

docker attach ant-ivy

3. Clone ivy project into the folder

git clone https://git-wip-us.apache.org/repos/asf/ant-ivy.git
cd ant-ivy
ant jar

4. copy the ivy.jar to /usr/share/ant/lib folder.

5. If you have any other files to copy from your local to running docker container use the following command.

docker cp fileToCopy ant-ivy:/folder_name

6. Once your configuration is complete, create a new image out of the running container.

docker commit ant-ivy docker.artifactory.rajan.com/rajan/ant_with_ivy:version_01

This command will create a new docker image out of the running ant-ivy container instance. (run it from different cmd as exit command from attached cmd will exit the container)

7. Login to the custom docker artifactory

docker login docker.artifactory.rajan.com

8. push the image to artifactory

docker push docker.artifactory.rajan.com/rajan/ant_with_ivy:version_01

Now if you do the following command from another machine, it will be able to get the docker image.

docker pull docker.artifactory.rajan.com/rajan/ant_with_ivy:version_01

That's all for today.
Hope this helps someone.

4 comments:

  1. Articles are commonly found in magazines, newspapers, and reputable websites, aiming to inform and educate readers. NordVPN Offer 3 Year Blogs often have a single author, while articles are frequently written by professional journalists.

    ReplyDelete

If you like to say anything (good/bad), Please do not hesitate...