You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steinar Bang <sb...@dod.no> on 2020/04/12 19:07:51 UTC

Re: Creating docker image from docker hub karaf image

The karaf-based docker examples I have seen build a custom karaf
distribution and then creates a Dockerfile that copies the custom karaf
distribution into /opt/apache-karaf in an image based one openjdk:8-jre.

What I would like to do, is to start with the official karaf image on
docker hub https://hub.docker.com/r/apache/karaf and then add a feature
as a part of the build process.

Unless I've misunderstood, the images will be a lot smaller, because
they will only hold the difference between the base image and the
current state of the image file system at the end of the build.

Here's what I have tried:
 1. Add the feature to shell.init.script (partly works, see previous
    email. But loads the feature at startup time so the behaviour may be
    different to what was expected)

 2. Fire up karaf and do commands to set the feature repository and add
    the feature (this failed miserably (as I expected, but I had to try))
     FROM apache/karaf:4.2.8
     COPY org.ops4j.pax.url.mvn.cfg /opt/apache-karaf/etc
     RUN karaf daemon
     RUN feature:repo-add mvn:no.priv.bang.ukelonn/karaf/LATEST/xml/features
     RUN feature:install ukelonn-with-derby
     RUN exit

 3. Fire up karaf as a deamon and then do ssh in to add the feature
    repository and install the feature (this started up the daemon and
    then got stuck)
     FROM apache/karaf:4.2.8
     COPY org.ops4j.pax.url.mvn.cfg /opt/apache-karaf/etc
     RUN karaf daemon
     RUN sshpass -p karaf ssh -p 8101 karaf@localhost 'feature:repo-add mvn:no.priv.bang.ukelonn/karaf/LATEST/xml/features'
     RUN sshpass -p karaf ssh -p 8101 karaf@localhost 'feature:install ukelonn-with-derby'
     RUN karaf stop

Are there any other ways this could be done?
Is there a way to copy in the bundles as loaded by a feature?


Re: Creating docker image from docker hub karaf image

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> Are there any other ways this could be done?

One possible way would be if the karaf-maven-plugin could build an
assembly that is identical to the assembly used to make the docker hub
image, and then add the new feature(s).

Then the diff to the docker hub image should only be the new feature(s).


Re: My first real karaf-based docker image: sonar-collector

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:

> Thanks for sharing !
> I think we can improve the docker script provided by Karaf to do the same (starting from Karaf official instance).

Sounds great! :-)

Resolving a feature like at startup and providing the bundles both from
dependencies and the reactor build into system directory of the karaf in
the container in some way would also be nice.

For my particular docker image it makes sense to provision from the
latest release on maven central (I don't have to rebuild the image when
I make a new release).

But for someone creating an image containing stuff not released to maven
central or creating an image from a snapshot build, or deploying to a
docker instance that's can't reach maven central, then it would be nice
to have all of the dependecies inside the image.


Re: My first real karaf-based docker image: sonar-collector

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Thanks for sharing !

I think we can improve the docker script provided by Karaf to do the same (starting from Karaf official instance).

Regards
JB

> Le 21 avr. 2020 à 18:36, Steinar Bang <sb...@dod.no> a écrit :
> 
> I have created my first real karaf-based docker image:
> https://github.com/steinarb/sonar-collector#run-the-sonar-metrics-collector-in-docker
> 
> The sonar-collector is intended as a webhook called by sonar on
> completing a build, it will store key sonar measurements as a row in a
> database table.  
> 
> Sonar has these numbers internally but doesn't have a way to get at
> them. At first we typed these numbers manually into a spreadsheet to get
> statistics on a set of analyzed programs.  But that was tedious, so we
> created sonar-collector to capture the numbers instead.
> 
> The docker image is built with maven against a local docker and then
> after testing, the image was pushed to docker hub:
> https://github.com/steinarb/sonar-collector#building-the-docker-image
> 
> The docker image is a very thin layer on top of the official karaf 4.2.8
> docker image
> https://github.com/steinarb/sonar-collector/blob/master/docker/docker/Dockerfile#L1
> 
> It copies in two files into the image's karaf etc directory:
> 1. org.apache.karaf.features.cfg
>    a. Adds a feature repository for sonar-collector
>        https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L28
>    b. Adds two features to the boot features
>       i. An enviroment variable overloadable DataSourceFactory feature
>          that defaults to postgresql
>            https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L52
>       ii. The sonar-collector-webhook-with-postgresql feature
>            https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L53
> 
> 2. org.ops4j.datasource-sonar-collector.cfg which is a modified version
>    of the file generated by pax-jdbc on first start, and the JDBC
>    driver name and JDBC connection info overridable by system
>    environment variables
>     https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.ops4j.datasource-sonar-collector.cfg#L2
> 
> This image will provision itself from maven central (sonar-collector is
> released to maven-central) and will always use the latest released
> version, so there is no need to build a new docker image if a new
> version of sonar-collector is released to maven central.
> 
> Since the database schema is set up by liquibase and the SQL used is
> trivial (inserts rows into a single table), it should in theory be
> possible to use a different database than PostgreSQL, and I have
> provided the possibility to override the database used when doing
> "docker run" of the image.
> 
> But using other databases than PostgreSQL is something I haven't
> extensively tested.
> 


Re: My first real karaf-based docker image: sonar-collector

Posted by Gerald Kallas <ca...@mailbox.org>.
Cool stuff. Like it!

> Steinar Bang <sb...@dod.no> hat am 21. April 2020 18:36 geschrieben:
> 
>  
> I have created my first real karaf-based docker image:
>  https://github.com/steinarb/sonar-collector#run-the-sonar-metrics-collector-in-docker
> 
> The sonar-collector is intended as a webhook called by sonar on
> completing a build, it will store key sonar measurements as a row in a
> database table.  
> 
> Sonar has these numbers internally but doesn't have a way to get at
> them. At first we typed these numbers manually into a spreadsheet to get
> statistics on a set of analyzed programs.  But that was tedious, so we
> created sonar-collector to capture the numbers instead.
> 
> The docker image is built with maven against a local docker and then
> after testing, the image was pushed to docker hub:
>  https://github.com/steinarb/sonar-collector#building-the-docker-image
> 
> The docker image is a very thin layer on top of the official karaf 4.2.8
> docker image
>  https://github.com/steinarb/sonar-collector/blob/master/docker/docker/Dockerfile#L1
> 
> It copies in two files into the image's karaf etc directory:
>  1. org.apache.karaf.features.cfg
>     a. Adds a feature repository for sonar-collector
>         https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L28
>     b. Adds two features to the boot features
>        i. An enviroment variable overloadable DataSourceFactory feature
>           that defaults to postgresql
>             https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L52
>        ii. The sonar-collector-webhook-with-postgresql feature
>             https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L53
> 
>  2. org.ops4j.datasource-sonar-collector.cfg which is a modified version
>     of the file generated by pax-jdbc on first start, and the JDBC
>     driver name and JDBC connection info overridable by system
>     environment variables
>      https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.ops4j.datasource-sonar-collector.cfg#L2
> 
> This image will provision itself from maven central (sonar-collector is
> released to maven-central) and will always use the latest released
> version, so there is no need to build a new docker image if a new
> version of sonar-collector is released to maven central.
> 
> Since the database schema is set up by liquibase and the SQL used is
> trivial (inserts rows into a single table), it should in theory be
> possible to use a different database than PostgreSQL, and I have
> provided the possibility to override the database used when doing
> "docker run" of the image.
> 
> But using other databases than PostgreSQL is something I haven't
> extensively tested.

Re: My first real karaf-based docker image: sonar-collector

Posted by Francois Papon <fr...@openobject.fr>.
Nice! 

Great job Steinar!

regards,

François
fpapon@apache.org

Le 21/04/2020 à 18:36, Steinar Bang a écrit :
> I have created my first real karaf-based docker image:
>  https://github.com/steinarb/sonar-collector#run-the-sonar-metrics-collector-in-docker
>
> The sonar-collector is intended as a webhook called by sonar on
> completing a build, it will store key sonar measurements as a row in a
> database table.  
>
> Sonar has these numbers internally but doesn't have a way to get at
> them. At first we typed these numbers manually into a spreadsheet to get
> statistics on a set of analyzed programs.  But that was tedious, so we
> created sonar-collector to capture the numbers instead.
>
> The docker image is built with maven against a local docker and then
> after testing, the image was pushed to docker hub:
>  https://github.com/steinarb/sonar-collector#building-the-docker-image
>
> The docker image is a very thin layer on top of the official karaf 4.2.8
> docker image
>  https://github.com/steinarb/sonar-collector/blob/master/docker/docker/Dockerfile#L1
>
> It copies in two files into the image's karaf etc directory:
>  1. org.apache.karaf.features.cfg
>     a. Adds a feature repository for sonar-collector
>         https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L28
>     b. Adds two features to the boot features
>        i. An enviroment variable overloadable DataSourceFactory feature
>           that defaults to postgresql
>             https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L52
>        ii. The sonar-collector-webhook-with-postgresql feature
>             https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L53
>
>  2. org.ops4j.datasource-sonar-collector.cfg which is a modified version
>     of the file generated by pax-jdbc on first start, and the JDBC
>     driver name and JDBC connection info overridable by system
>     environment variables
>      https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.ops4j.datasource-sonar-collector.cfg#L2
>
> This image will provision itself from maven central (sonar-collector is
> released to maven-central) and will always use the latest released
> version, so there is no need to build a new docker image if a new
> version of sonar-collector is released to maven central.
>
> Since the database schema is set up by liquibase and the SQL used is
> trivial (inserts rows into a single table), it should in theory be
> possible to use a different database than PostgreSQL, and I have
> provided the possibility to override the database used when doing
> "docker run" of the image.
>
> But using other databases than PostgreSQL is something I haven't
> extensively tested.
>

My first real karaf-based docker image: sonar-collector

Posted by Steinar Bang <sb...@dod.no>.
I have created my first real karaf-based docker image:
 https://github.com/steinarb/sonar-collector#run-the-sonar-metrics-collector-in-docker

The sonar-collector is intended as a webhook called by sonar on
completing a build, it will store key sonar measurements as a row in a
database table.  

Sonar has these numbers internally but doesn't have a way to get at
them. At first we typed these numbers manually into a spreadsheet to get
statistics on a set of analyzed programs.  But that was tedious, so we
created sonar-collector to capture the numbers instead.

The docker image is built with maven against a local docker and then
after testing, the image was pushed to docker hub:
 https://github.com/steinarb/sonar-collector#building-the-docker-image

The docker image is a very thin layer on top of the official karaf 4.2.8
docker image
 https://github.com/steinarb/sonar-collector/blob/master/docker/docker/Dockerfile#L1

It copies in two files into the image's karaf etc directory:
 1. org.apache.karaf.features.cfg
    a. Adds a feature repository for sonar-collector
        https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L28
    b. Adds two features to the boot features
       i. An enviroment variable overloadable DataSourceFactory feature
          that defaults to postgresql
            https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L52
       ii. The sonar-collector-webhook-with-postgresql feature
            https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L53

 2. org.ops4j.datasource-sonar-collector.cfg which is a modified version
    of the file generated by pax-jdbc on first start, and the JDBC
    driver name and JDBC connection info overridable by system
    environment variables
     https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.ops4j.datasource-sonar-collector.cfg#L2

This image will provision itself from maven central (sonar-collector is
released to maven-central) and will always use the latest released
version, so there is no need to build a new docker image if a new
version of sonar-collector is released to maven central.

Since the database schema is set up by liquibase and the SQL used is
trivial (inserts rows into a single table), it should in theory be
possible to use a different database than PostgreSQL, and I have
provided the possibility to override the database used when doing
"docker run" of the image.

But using other databases than PostgreSQL is something I haven't
extensively tested.


Re: Creating docker image from docker hub karaf image

Posted by Mike Hummel <mh...@mhus.de>.
Hi,

I did not read the hole tread but I solved a lot of problems with karaf in docker containers already.

There is also a small readme and also examples...

Container Sources:
https://github.com/mhus/mhus-docker/tree/master/apache-karaf/4.2.6_04 <https://github.com/mhus/mhus-docker/tree/master/apache-karaf/4.2.6_04>

Hub:
https://hub.docker.com/r/mhus/apache-karaf <https://hub.docker.com/r/mhus/apache-karaf>

Example:
https://github.com/mhus/cherry-reactive/tree/master/assembly/reactive-playground-docker <https://github.com/mhus/cherry-reactive/tree/master/assembly/reactive-playground-docker>

The idea is to provide a karaf docker base container. You can add the assembly and configurations (and profiles). And start it while build one time to collect all the resources you need. Background is a fast startup in kubernetes.

You can also mount a local repository to use bundle:watch for development. - That was the point - I think so. As described in the readme.

Regards,
Mike



> On 14. Apr 2020, at 18:53, Alex Soto <al...@envieta.com> wrote:
> 
> Agree, and perhaps the "data/cache”, and/or whatever else is needed to run without connecting the internet
> 
> 
> 
>> On Apr 14, 2020, at 11:22 AM, Steinar Bang <sb@dod.no <ma...@dod.no>> wrote:
>> 
>>>>>>> Jean-Baptiste Onofre <jb@nanthrax.net <ma...@nanthrax.net>>:
>> 
>>> What do you think about a small example/tooling addition to simplify this ?
>> 
>> I think that if you can use karaf's feature resolver to populate the
>> system directory, that would be awsome! :-)
>> 
>> 
> 


Re: Creating docker image from docker hub karaf image

Posted by Alex Soto <al...@envieta.com>.
Agree, and perhaps the "data/cache”, and/or whatever else is needed to run without connecting the internet



> On Apr 14, 2020, at 11:22 AM, Steinar Bang <sb...@dod.no> wrote:
> 
>>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:
> 
>> What do you think about a small example/tooling addition to simplify this ?
> 
> I think that if you can use karaf's feature resolver to populate the
> system directory, that would be awsome! :-)
> 
> 


Re: Creating docker image from docker hub karaf image

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:

> What do you think about a small example/tooling addition to simplify this ?

I think that if you can use karaf's feature resolver to populate the
system directory, that would be awsome! :-)



Re: Creating docker image from docker hub karaf image

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
What do you think about a small example/tooling addition to simplify this ?

By the way, a bit related, I will send updates and details about Karaf DevX by the end of this week. Stay tuned ;) 

Regards
JB

> Le 14 avr. 2020 à 14:58, Alex Soto <al...@envieta.com> a écrit :
> 
> I am working now on a similar task. I have pre-populated the maven repository directory (~/.m2/repository) from the container that made the build (I am using multi-stage images),  and set
> 
> 		org.ops4j.pax.url.mvn.localRepository=/root/.m2/repository
> 
> In `etc/org.ops4j.pax.url.mvn.cfg`.   
> 
> 
> Is there anything else I need to make the image self contained?  JB, can you elaborate about your reference to the system folder?
> 
> 
> Best regards,
> Alex soto
> 
> 
> 
> 
>> On Apr 14, 2020, at 2:13 AM, Jean-Baptiste Onofre <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
>> 
>> Hi,
>> 
>> For the startup, you can already populate the system folder (by hand or using mvn deploy:deploy-file or mvn install:install-file).
>> 
>> That’s what I’m doing in docker image preparation.
>> 
>> Regards
>> JB
>> 
>>> Le 13 avr. 2020 à 21:09, Steinar Bang <sb@dod.no <ma...@dod.no>> a écrit :
>>> 
>>> I have successfully created a docker image for my demo application based
>>> on the official karaf 4.2.8 docker hub image.
>>> 
>>> Here's what I did:
>>> 
>>> 1. Copied etc/org.ops4j.pax.url.mvn.cfg from a karaf 4.2.8 instance,
>>>   and added my own maven repo
>>>    https://gist.github.com/steinarb/62a070f6481d3e84c334a78f1c771e80#file-org-ops4j-pax-url-mvn-cfg-L113 <https://gist.github.com/steinarb/62a070f6481d3e84c334a78f1c771e80#file-org-ops4j-pax-url-mvn-cfg-L113>
>>> 
>>> 2. Copied org.apache.karaf.features.cfg and added the feature repo of
>>>   the sample application
>>>    https://gist.github.com/steinarb/fec331bcd37a0a7bdba850d33fcd0555#file-org-apache-karaf-features-cfg-L28 <https://gist.github.com/steinarb/fec331bcd37a0a7bdba850d33fcd0555#file-org-apache-karaf-features-cfg-L28>
>>>   and added the sample application to the list of boot features
>>>    https://gist.github.com/steinarb/fec331bcd37a0a7bdba850d33fcd0555#file-org-apache-karaf-features-cfg-L52 <https://gist.github.com/steinarb/fec331bcd37a0a7bdba850d33fcd0555#file-org-apache-karaf-features-cfg-L52>
>>> 
>>> 3. Created a Dockerfile adding to the official docker hub karaf 4.2.8
>>>   image, copying in the two modified config files
>>>    https://gist.github.com/steinarb/444ad82a63dcf156101a064666ed590c#file-dockerfile-L1 <https://gist.github.com/steinarb/444ad82a63dcf156101a064666ed590c#file-dockerfile-L1>
>>> 
>>> 4. Built the image from the Dockerfile
>>>    docker build -t steinarb/ukelonn-demo:v2 .
>>> 
>>> 5. Started the image
>>>    docker run -p 8101:8101 -p 8181:8181 -d steinarb/ukelonn-demo:v2
>>> 
>>> 6. The container took a while to start but eventually I could connect
>>>   to http://localhost:8181/ukelonn <http://localhost:8181/ukelonn> where I found the demo version of
>>>   my application running 
>>> 
>>> The downsides of this approach, are:
>>> 1. Container startup is slow since features and their dependencies must
>>>   be downloaded
>>> 
>>> 2. The maven repons may not be reachable at startup time and container
>>>   startup will fail
>>> 
>>> 3. What the maven repos serve may potensially not be the same on each
>>>   startup
>>> 
>>> All of the above is, I guess, sort of contrary to docker philosophy,
>>> which is to pack up everything the application needs to start, so that
>>> the application can be started in a predictable and reproducable manner.
>>> 
>>> However, for this particular application, this is actually what I want:
>>> I can create a docker image and deploy to docker hub, and on any docker
>>> installation that can pull from dockerhub and can reach internet, I can
>>> spin up the latest snapshot with the two commands "docker pull" and
>>> "docker run".
>>> 
>> 
> 


Re: Creating docker image from docker hub karaf image

Posted by Alex Soto <al...@envieta.com>.
I am working now on a similar task. I have pre-populated the maven repository directory (~/.m2/repository) from the container that made the build (I am using multi-stage images),  and set

		org.ops4j.pax.url.mvn.localRepository=/root/.m2/repository

In `etc/org.ops4j.pax.url.mvn.cfg`.   


Is there anything else I need to make the image self contained?  JB, can you elaborate about your reference to the system folder?


Best regards,
Alex soto




> On Apr 14, 2020, at 2:13 AM, Jean-Baptiste Onofre <jb...@nanthrax.net> wrote:
> 
> Hi,
> 
> For the startup, you can already populate the system folder (by hand or using mvn deploy:deploy-file or mvn install:install-file).
> 
> That’s what I’m doing in docker image preparation.
> 
> Regards
> JB
> 
>> Le 13 avr. 2020 à 21:09, Steinar Bang <sb...@dod.no> a écrit :
>> 
>> I have successfully created a docker image for my demo application based
>> on the official karaf 4.2.8 docker hub image.
>> 
>> Here's what I did:
>> 
>> 1. Copied etc/org.ops4j.pax.url.mvn.cfg from a karaf 4.2.8 instance,
>>   and added my own maven repo
>>    https://gist.github.com/steinarb/62a070f6481d3e84c334a78f1c771e80#file-org-ops4j-pax-url-mvn-cfg-L113
>> 
>> 2. Copied org.apache.karaf.features.cfg and added the feature repo of
>>   the sample application
>>    https://gist.github.com/steinarb/fec331bcd37a0a7bdba850d33fcd0555#file-org-apache-karaf-features-cfg-L28
>>   and added the sample application to the list of boot features
>>    https://gist.github.com/steinarb/fec331bcd37a0a7bdba850d33fcd0555#file-org-apache-karaf-features-cfg-L52
>> 
>> 3. Created a Dockerfile adding to the official docker hub karaf 4.2.8
>>   image, copying in the two modified config files
>>    https://gist.github.com/steinarb/444ad82a63dcf156101a064666ed590c#file-dockerfile-L1
>> 
>> 4. Built the image from the Dockerfile
>>    docker build -t steinarb/ukelonn-demo:v2 .
>> 
>> 5. Started the image
>>    docker run -p 8101:8101 -p 8181:8181 -d steinarb/ukelonn-demo:v2
>> 
>> 6. The container took a while to start but eventually I could connect
>>   to http://localhost:8181/ukelonn where I found the demo version of
>>   my application running 
>> 
>> The downsides of this approach, are:
>> 1. Container startup is slow since features and their dependencies must
>>   be downloaded
>> 
>> 2. The maven repons may not be reachable at startup time and container
>>   startup will fail
>> 
>> 3. What the maven repos serve may potensially not be the same on each
>>   startup
>> 
>> All of the above is, I guess, sort of contrary to docker philosophy,
>> which is to pack up everything the application needs to start, so that
>> the application can be started in a predictable and reproducable manner.
>> 
>> However, for this particular application, this is actually what I want:
>> I can create a docker image and deploy to docker hub, and on any docker
>> installation that can pull from dockerhub and can reach internet, I can
>> spin up the latest snapshot with the two commands "docker pull" and
>> "docker run".
>> 
> 


Re: Creating docker image from docker hub karaf image

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi,

For the startup, you can already populate the system folder (by hand or using mvn deploy:deploy-file or mvn install:install-file).

That’s what I’m doing in docker image preparation.

Regards
JB

> Le 13 avr. 2020 à 21:09, Steinar Bang <sb...@dod.no> a écrit :
> 
> I have successfully created a docker image for my demo application based
> on the official karaf 4.2.8 docker hub image.
> 
> Here's what I did:
> 
> 1. Copied etc/org.ops4j.pax.url.mvn.cfg from a karaf 4.2.8 instance,
>    and added my own maven repo
>     https://gist.github.com/steinarb/62a070f6481d3e84c334a78f1c771e80#file-org-ops4j-pax-url-mvn-cfg-L113
> 
> 2. Copied org.apache.karaf.features.cfg and added the feature repo of
>    the sample application
>     https://gist.github.com/steinarb/fec331bcd37a0a7bdba850d33fcd0555#file-org-apache-karaf-features-cfg-L28
>    and added the sample application to the list of boot features
>     https://gist.github.com/steinarb/fec331bcd37a0a7bdba850d33fcd0555#file-org-apache-karaf-features-cfg-L52
> 
> 3. Created a Dockerfile adding to the official docker hub karaf 4.2.8
>    image, copying in the two modified config files
>     https://gist.github.com/steinarb/444ad82a63dcf156101a064666ed590c#file-dockerfile-L1
> 
> 4. Built the image from the Dockerfile
>     docker build -t steinarb/ukelonn-demo:v2 .
> 
> 5. Started the image
>     docker run -p 8101:8101 -p 8181:8181 -d steinarb/ukelonn-demo:v2
> 
> 6. The container took a while to start but eventually I could connect
>    to http://localhost:8181/ukelonn where I found the demo version of
>    my application running 
> 
> The downsides of this approach, are:
> 1. Container startup is slow since features and their dependencies must
>    be downloaded
> 
> 2. The maven repons may not be reachable at startup time and container
>    startup will fail
> 
> 3. What the maven repos serve may potensially not be the same on each
>    startup
> 
> All of the above is, I guess, sort of contrary to docker philosophy,
> which is to pack up everything the application needs to start, so that
> the application can be started in a predictable and reproducable manner.
> 
> However, for this particular application, this is actually what I want:
> I can create a docker image and deploy to docker hub, and on any docker
> installation that can pull from dockerhub and can reach internet, I can
> spin up the latest snapshot with the two commands "docker pull" and
> "docker run".
> 


Re: Creating docker image from docker hub karaf image

Posted by Steinar Bang <sb...@dod.no>.
I have successfully created a docker image for my demo application based
on the official karaf 4.2.8 docker hub image.

Here's what I did:

 1. Copied etc/org.ops4j.pax.url.mvn.cfg from a karaf 4.2.8 instance,
    and added my own maven repo
     https://gist.github.com/steinarb/62a070f6481d3e84c334a78f1c771e80#file-org-ops4j-pax-url-mvn-cfg-L113

 2. Copied org.apache.karaf.features.cfg and added the feature repo of
    the sample application
     https://gist.github.com/steinarb/fec331bcd37a0a7bdba850d33fcd0555#file-org-apache-karaf-features-cfg-L28
    and added the sample application to the list of boot features
     https://gist.github.com/steinarb/fec331bcd37a0a7bdba850d33fcd0555#file-org-apache-karaf-features-cfg-L52

 3. Created a Dockerfile adding to the official docker hub karaf 4.2.8
    image, copying in the two modified config files
     https://gist.github.com/steinarb/444ad82a63dcf156101a064666ed590c#file-dockerfile-L1

 4. Built the image from the Dockerfile
     docker build -t steinarb/ukelonn-demo:v2 .

 5. Started the image
     docker run -p 8101:8101 -p 8181:8181 -d steinarb/ukelonn-demo:v2

 6. The container took a while to start but eventually I could connect
    to http://localhost:8181/ukelonn where I found the demo version of
    my application running 

The downsides of this approach, are:
 1. Container startup is slow since features and their dependencies must
    be downloaded

 2. The maven repons may not be reachable at startup time and container
    startup will fail

 3. What the maven repos serve may potensially not be the same on each
    startup

All of the above is, I guess, sort of contrary to docker philosophy,
which is to pack up everything the application needs to start, so that
the application can be started in a predictable and reproducable manner.

However, for this particular application, this is actually what I want:
I can create a docker image and deploy to docker hub, and on any docker
installation that can pull from dockerhub and can reach internet, I can
spin up the latest snapshot with the two commands "docker pull" and
"docker run".


Re: Creating docker image from docker hub karaf image

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> What I would like to do, is to start with the official karaf image on
> docker hub https://hub.docker.com/r/apache/karaf and then add a feature
> as a part of the build process.

> Unless I've misunderstood, the images will be a lot smaller, because
> they will only hold the difference between the base image and the
> current state of the image file system at the end of the build.

Hm... I've looked at the file system state of a priestine karaf 4.2.8
docker image, and maybe this wasn't such a good idea after all?
 https://hub.docker.com/layers/apache/karaf/4.2.8/images/sha256-90ab8758ddddf4f0b28afe7ca24b67456a9a8619be4cf5fc2fa90e3b26e64adf?context=explore

A priestine karaf 4.2.8 image as an almost empty data directory, and the
first thing that happens when karaf is started, is that e.g. data/cache/
is filled up with the running bundles, so the file system delta will be
pretty big anyway. 

I.e. there will not be much space saved by this approach.