maven docker plugin fabric8 – Little Big Extra http://littlebigextra.com A technology blog covering topics on Java, Scala, Docker, AWS, BigData, DevOps and much more to come. Do it yourself instructions for complex to simple problems for a novice to an expert. Mon, 01 Apr 2019 14:18:04 +0000 en-US hourly 1 https://wordpress.org/?v=5.1.1 http://littlebigextra.com/wp-content/uploads/2023/04/cropped-logo-32x32.png maven docker plugin fabric8 – Little Big Extra http://littlebigextra.com 32 32 Using Jenkins to Build and Deploy Docker images http://littlebigextra.com/using-jenkins-to-build-and-deploy-docker-images/ http://littlebigextra.com/using-jenkins-to-build-and-deploy-docker-images/#respond Fri, 28 Apr 2023 16:06:19 +0000 http://littlebigextra.com/?p=933 How to use Jenkins to Build and Deploy docker images without Jenkins Docker plugin Introduction Jenkins is one of the most popular continuous integration tools and is widely used. It can be used to create pipelines, run jobs and do automated deployments. There are many plugins available which can be added to Jenkins and makes it […]

The post Using Jenkins to Build and Deploy Docker images appeared first on Little Big Extra.

]]>
How to use Jenkins to Build and Deploy docker images without Jenkins Docker plugin

Introduction

Jenkins is one of the most popular continuous integration tools and is widely used. It can be used to create pipelines, run jobs and do automated deployments.
There are many plugins available which can be added to Jenkins and makes it really powerful.

Recently I wanted to do an automated deployment of Docker Images to docker server and tried using docker-plugin but after spending some time it looked to me that if it asking for too much of information and for each operation you need to provide arguments, I would prefer a solution which is more dynamic and picks things automatically with user providing the bare essentials parameters arguments.
This is how it looks like

 

In a nutshell, all I wanted was

  • Jenkins to automatically start building the Docker Image once the code is pushed to GIT.
  • The Image should be deployed to remote docker host and it should start the container

How to do it

  • Well, the first step is is to enable Jenkins to auto build with BitBucket server or other code repository server. If you want your build process to start as soon as the code is committed to GIT repository.
    Here is an example of how to enable with BitBucket Server, for other GIT repositories servers like GITHUB Jenkins does have different plugins.In case you want to build process to start manually or periodically you can skip this step.

  • Once the build is automated.The second step is to enable Remote API on Docker Host.Docker provides remote REST API which is beneficial if you want to connect to a remote docker host, this API allows you do to set of operations from creating and managing containers to start to stop containers.This step is pivotal before we move on to next step.
  • The third step is to modify your pom to build and deploy Docker Image, well this is the key step as in this step you will be literally doing all the stuff from creating the image to build the image and start the container.

    Once all 3 steps have been tested and completed all is left to be done in Jenkins is to Invoke the clean install goal as shown below.

Jenkins Build step

If you want to push the docker image to some repository after building, testing and deploying.Please follow this link

The post Using Jenkins to Build and Deploy Docker images appeared first on Little Big Extra.

]]> http://littlebigextra.com/using-jenkins-to-build-and-deploy-docker-images/feed/ 0 How To Push Docker Images To Docker Hub Repository Using Docker Maven plugin http://littlebigextra.com/push-docker-images-docker-hub-using-maven/ http://littlebigextra.com/push-docker-images-docker-hub-using-maven/#comments Sat, 25 Mar 2023 12:15:07 +0000 http://littlebigextra.com/?p=501 Push a Docker image to DockerHub using docker maven plugin fabric8.io   Introduction If you want to push a docker image to Docker Hub repository, it can be achieved using docker maven plugin from fabric8.io. This plugin lets you build images, start and stop containers and push it to Docker repositories In case you are wondering […]

The post How To Push Docker Images To Docker Hub Repository Using Docker Maven plugin appeared first on Little Big Extra.

]]>
Push a Docker image to DockerHub using docker maven plugin fabric8.io

 

Introduction

If you want to push a docker image to Docker Hub repository, it can be achieved using docker maven plugin from fabric8.io. This plugin lets you build images, start and stop containers and push it to Docker repositories

In case you are wondering the difference between a container and image, please note that in docker terminology a running image is called container.
In this tutorial, we are going to

  • Build a docker image
  • Push image to Docker Hub repository

&nsbp;

Want to build a docker image first using this plugin ?
Read Here : How to Build a Docker Image and start stop container
  1. For the below example, I have used Spring Boot Rest service project which is connected to MongoDB. See below link for reference.
  2. Using io.fabric8 plugin, under the plugin section add the io.fabric8 plugin
    <plugin>
    	<groupId>io.fabric8</groupId>
    	<artifactId>docker-maven-plugin</artifactId>
    	<version>0.20.0</version>....

  3. We need to first build the image from Dockerfile, this plugin supports all the command which are in Dockerfile and you can directly create a docker image by giving arguments in pom.xml but In my view making docker images from Docker file is much easier and simpler. So we will ask maven plugin in below step to look for Dockerfile in root( project base directory)
    <name>springboot-mongo-dockerimage:${project.version}</name>
        <alias>springboot-mongo-dockerimage</alias>
    <build>
        <dockerFileDir>${project.basedir}</dockerFileDir>
    </build>
  4. Next we specify the docker registry address
    <registry>registry.hub.docker.com/YOUR_DOCKER_HUB_USERNAME</registry>
  5. Now we need to add authentication credentials in <authconfig> tag
    <authConfig>
    	<username>ENTER YOUR DOCKER HUB USERNAME LIKE abhishek</username>
    	<password>ENTER YOUR DOCKER HUB PASSWORD</password>
    </authConfig>
  6. We will add execution phases, where we will push the image
    <execution>
    	<id>push</id>
    	<phase>post-integration-test</phase>
    	<goals>
    		<goal>push</goal>
    	</goals>
    </execution>
  7. Now run the pom.xml using mvn clean install and check your docker hub repo after some time to see if image has been pushed. If you are pushing the image for first time its gonna take some time  depending on the size of image.

Here is the complete build section from the plugin, hope this help.

<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>io.fabric8</groupId>
				<artifactId>docker-maven-plugin</artifactId>
				<version>0.20.0</version>
				<configuration>
					<registry>registry.hub.docker.com/YOUR_DOCKER_HUB_USERNAME</registry>

					<images>
						<image>
							<name>springboot-mongo-dockerhub:${project.version}</name>
							<alias>springboot-mongo-dockerhub</alias>
							<build>
								<dockerFileDir>${project.basedir}</dockerFileDir>

							</build>
							<run>
								<namingStrategy>alias</namingStrategy>
								<dependsOn>
									<container>mongo</container>
								</dependsOn>

								<links>
									<link>mongo</link>
								</links>
								<ports>
									<port>9876:8080</port>
								</ports>
								<log>
									<prefix>TC</prefix>
									<date>default</date>
									<color>cyan</color>
								</log>
							</run>
						</image>
					</images>
					<authConfig>
						<username>ENTER YOUR DOCKER HUB USERNAME LIKE abhishek</username>
						<password>ENTER YOUR DOCKER HUB PASSWORD</password>
					</authConfig>
				</configuration>

				<executions>
					<execution>
						<id>start</id>
						<phase>pre-integration-test</phase>
						<goals>
							<goal>stop</goal>
							<goal>build</goal>
							<goal>start</goal>
						</goals>
					</execution>
					<execution>
						<id>push</id>
						<phase>post-integration-test</phase>
						<goals>
							<goal>stop</goal>
							<goal>push</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

 

 

If you get an error : io.fabric8:docker-maven-plugin:0.20.0:build failed: A tar file cannot include itself

How to fix- A tar file cannot include itself

The post How To Push Docker Images To Docker Hub Repository Using Docker Maven plugin appeared first on Little Big Extra.

]]>
http://littlebigextra.com/push-docker-images-docker-hub-using-maven/feed/ 2
Build and deploy Docker Image with Docker Maven plugin http://littlebigextra.com/build-deploy-docker-image-maven/ http://littlebigextra.com/build-deploy-docker-image-maven/#comments Wed, 08 Mar 2023 12:04:28 +0000 http://littlebigextra.com/?p=451 Build a Docker Image and Run a Docker Container with docker maven plugin fabric8.io   Introduction  The maven plugin for docker fabric8io/docker-maven-plugin helps us in building docker images and running containers. In case you are thinking about the difference between an image and container then please note that a running image is called container. In this […]

The post Build and deploy Docker Image with Docker Maven plugin appeared first on Little Big Extra.

]]>
Build a Docker Image and Run a Docker Container with docker maven plugin fabric8.io

 

Introduction

 The maven plugin for docker fabric8io/docker-maven-plugin helps us in building docker images and running containers. In case you are thinking about the difference between an image and container then please note that a running image is called container.

In this tutorial, we are going to

  • Build a docker image
  • Link it to running DB container (Mongo)
  • Start the container
  • Stop the container
Please note that Docker and Jenkins were both running on Centos (Linux) as separate processes
  1. For below steps, I have used Spring Boot Rest service project which is connected to MongoDB. See below link for reference.
  2. Using io.fabric8 plugin, under the plugin section add the io.fabric8 plugin
    <plugin>
    	<groupId>io.fabric8</groupId>
    	<artifactId>docker-maven-plugin</artifactId>
    	<version>0.20.0</version>....
  3. We need to first build the image from Dockerfile, this plugin supports all the command which are in Dockerfile but I think making docker image from Docker file is much easier and simpler. So I telling the maven plugin in below step to look for Dockerfile in root( project base directory)
    <name>springboot-mongo-dockerimage:${project.version}</name>
        <alias>springboot-mongo-dockerimage</alias>
    <build>
        <dockerFileDir>${project.basedir}</dockerFileDir>
    </build>
  4. Next step is to specify what docker container needs to do when it runs.
    1. Since we want to make sure that mongo DB container should be running before this image starts running. We add a tag called <dependsOn>.
    2. If the MongoDB is started we would like to link this container to Mongo so both can talk to each other, we specify that by adding a tag called <link>
      <dependsOn>
      	<container>mongo</container>
      </dependsOn>
      <links>
      	<link>mongo</link>
      </links>
    3. Next, we will specify on which port we would like to run this container and which port it should map to localhost machine
      <ports>
      <port>9876:8080</port>
      </ports>
    4. We enable all the logging using <log> tag, so we could see any errors or debug if some problem arises.
  5. Next, we will add execution phases, we will cover these steps
    1. Remove an existing image, if it exists
    2. Build the Image
    3. Deploy the image
      <executions>
      	<execution>
      	        <id>start</id>
      		<phase>pre-integration-test</phase>
      		<goals>
                          <goal>stop</goal>
      		    <goal>build</goal>
      		    <goal>start</goal>
      							
      	</goals>
      </execution>
  6. Now run this pom.xml using mvn clean install and check your docker containers so see if it running.

Here is the complete build section from the plugin, hope this help.

<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>io.fabric8</groupId>
				<artifactId>docker-maven-plugin</artifactId>
				<version>0.20.0</version>
				<configuration>
					<!--<dockerHost>tcp://REMOTE_IP:2375</dockerHost>-->
					<images>
						<image>
							<name>springboot-mongo-dockerimage:${project.version}</name>
							<alias>springboot-mongo-dockerimage</alias>
							<build>
								<dockerFileDir>${project.basedir}</dockerFileDir>
 
							</build>
							<run>
								<namingStrategy>alias</namingStrategy>
								<dependsOn>
									<container>mongo</container>
								</dependsOn>
 
								<links>
									<link>mongo</link>
								</links>
								<ports>
									<port>9876:8080</port>
								</ports>
								<log>
									<prefix>TC</prefix>
									<date>default</date>
									<color>cyan</color>
								</log>
							</run>
 
						</image>
					</images>
				</configuration>
 
				<executions>
					<execution>
						<id>start</id>
						<phase>pre-integration-test</phase>
						<goals>
							<goal>stop</goal>
							<goal>build</goal>
							<goal>start</goal>
						</goals>
					</execution>
                               <!-- Uncommment this execution phase if you wan to remove container after testing ->
					<!--<execution>
						<id>clean image</id>
						<phase>post-integration-test</phase>
						<goals>
							<goal>stop</goal>
						</goals>
					</execution> -->
				</executions>
			</plugin>
		</plugins>
	</build>

If you get an error : io.fabric8:docker-maven-plugin:0.20.0:build failed: A tar file cannot include itself

The post Build and deploy Docker Image with Docker Maven plugin appeared first on Little Big Extra.

]]>
http://littlebigextra.com/build-deploy-docker-image-maven/feed/ 5