It’s more or less what docker:provision is doing ;)

Regards
JB

> Le 7 avr. 2020 à 17:52, Gerald Kallas <catsh...@mailbox.org> a écrit :
> 
> Hi, that's the way I did w/ Camel on Karaf
> 
> 1. Start karaf
> 
> cd /opt
> unzip /home/karaf/apache-karaf-4.2.7.zip
> ln -s /opt/apache-karaf* /opt/apache-karaf
> cd apache-karaf/bin
> ./karaf
> 
> 2. Install the needed features (in a 2nd SSH session)
> 
> cd /opt/apache-karaf/bin
> ./client < karaf.sh
> 
> karaf.sh looks like
> 
> feature:repo-add hawtio 2.9.1
> feature:repo-add activemq 5.15.11
> feature:repo-add camel 3.1.0
> feature:install webconsole hawtio activemq-broker-noweb camel camel-jms jms 
> camel-http camel-jetty camel-swagger-java camel-ftp camel-jackson 
> camel-jsonpath camel-zipfile camel-velocity camel-groovy
> 
> 3. Package the archive file of the ready-to-run karaf
> 
> ^D
> tar -czvf apache-karaf-4.2.7-camel-3.0.1.tgz apache-karaf-4.2.7
> cp apache-karaf apache-karaf-4.2.7-apache-camel-3.0.1.tgz /home/karaf
> 
> 4. Build the docker container based on the created archive, the Dockerfile 
> and docker-compose
> 
> docker-compose up --build -d
> 
> Dockerfile looks like
> 
> FROM openjdk:8-jre
> 
> # Set karaf environment variables
> ENV KARAF_INSTALL_PATH /opt
> ENV KARAF_HOME $KARAF_INSTALL_PATH/apache-karaf
> ENV PATH $PATH:$KARAF_HOME/bin
> 
> # The karaf_dist can point to a directory or a tarball on the local system
> ARG karaf_dist=apache-karaf-4.2.7-camel-3.0.1.tgz
> 
> # Install build dependencies and karaf
> ADD $karaf_dist $KARAF_INSTALL_PATH
> RUN set -x && \
>  ln -s $KARAF_INSTALL_PATH/apache-karaf* $KARAF_HOME
> 
> # Create karaf user
> RUN groupadd --gid 2000 karaf && \
>    useradd --uid 2000 --create-home --home-dir /var/karaf --gid karaf karaf
> 
> # Set user permissions
> RUN mkdir -p /var/karaf/files && \
>    mkdir /opt/apache-karaf/templates && \
>    chown -R karaf:karaf /var/karaf && \
>    chown -R karaf:karaf /opt/apache-karaf*
> 
> EXPOSE 8101 1099 44444 8181 8443
> USER karaf
> CMD ["karaf", "run"]
> 
> docker-compose looks like
> 
> services:
>  karaf:
>    container_name: karaf
>    user: "2000"
>    build: .
>    restart: unless-stopped
>    network_mode: bridge
>    ports:
>      - "8101:8101"
>      - "1099:1099"
>      - "44444:44444"
>      - "8181:8181"
>      - "8443:8443"
>      - "8182:8182"
>      - "8444:8444"
>    volumes:
>      - /var/karaf/etc:/opt/apache-karaf/etc
>      - /var/karaf/deploy:/opt/apache-karaf/deploy
>      - /var/karaf/templates:/opt/apache-karaf/templates
>      - /var/karaf/files:/var/casisp/files
>    command: karaf
>    stdin_open: true
>    tty: true
> 
> So far I'm exposing the 4 directories
> 
> karaf/etc
> karaf/deploy
> karaf/templates (for Velocity templates we're using)
> karaf/files (for file component consumer and producer)
> 
> For me it works well. I've to do a little bit of improvement
> 
> 1. The .m2 Maven directory isn't included yet within the container, so far 
> ist shows some warnings while starting offline
> 2. Active MQ shows in offline start mode an error because one file is missing
> 
> Both I'm going to solve within the next couple of days.
> 
> Best
> - Gerald
> 
>> Steinar Bang <s...@dod.no> hat am 7. April 2020 14:23 geschrieben:
>> 
>> 
>>>>>>> Steinar Bang <s...@dod.no>:
>> 
>>> Is there a way to flush what docker:provision has made?
>> 
>> Yes.  Use the "docker" command on the host (docker installed with
>> "apt install docker.io" on a debian stable system):
>>  docker rm -vf $(docker ps -a -q)
>>  docker rmi -f $(docker images -a -q)
>> 
>> Source: https://stackoverflow.com/a/44785784
>> 
>>> And is there a way to extract the image docker:provision has made and
>>> make it into something that can be pushed to dockerhub?
>> 
>> Yes. I did the following:
>> 1. Created the repo ukelonn-demo on docker hub: 
>> https://hub.docker.com/repository/docker/steinarb/ukelonn-demo/tags?page=1
>> 
>> 2. Ran the commands above to clear out the local docker instance of all 
>> images
>> 
>> 3. Logged the docker instance on my local machine (the one running both
>>    karaf and dockerd):
>>     docker login --username=yourhubusername --email=yourem...@company.com
>> 
>> 4. In karaf, deleted the data directory to start fresh, started karaf
>>    and populated karaf with features, and provisioned the running karaf
>>    (note: this requires my own maven repo, and karaf already had that):
>>     feature:repo-add mvn:no.priv.bang.ukelonn/karaf/LATEST/xml/features
>>     feature:install ukelonn-with-derby
>>     feature:install docker
>>     docker:provision ukelonn-demo
>> 
>> 5. Ran "docker images" to find the id of the provisioned karaf instance
>>    (at this point it was the only image in the local docker)
>>     sb@lorenzo:~$ docker images
>>     REPOSITORY          TAG                 IMAGE ID            CREATED
>>     SIZE
>>     java                8-jre-alpine        fdc893b19a14        3 years
>>     ago         108MB
>>     sb@lorenzo:~$
>> 
>> 6. Created a tag using my dockerhub username, the name of the repo I'd
>>    created and the date and time of day:
>>     sb@lorenzo:~$ docker tag fdc893b19a14 steinarb/ukelonn-demo:202004071205
>>     sb@lorenzo:~$
>> 
>> 7. Pushed the tag to docker hub:
>>     sb@lorenzo:~$ docker push steinarb/ukelonn-demo:202004071205
>>     The push refers to repository [docker.io/steinarb/ukelonn-demo]
>>     20dd87a4c2ab: Mounted from library/java
>>     78075328e0da: Mounted from library/java
>>     9f8566ee5135: Mounted from library/java
>>     202004071205: digest:
>>     sha256:6a8cbe4335d1a5711a52912b684e30d6dbfab681a6733440ff7241b05a5deefd
>>     size: 947
>>     sb@lorenzo:~$
>> 
>> 8. Opened https://labs.play-with-docker.com in a web browser and
>>    clicked on "Start"
>> 
>> 9. In the command shell, pulled the image from docker hub:
>>     docker pull steinarb/ukelonn-demo:202004071205
>> 
>> 10. Tried running the image, but that failed with "no command specified":
>>     [node1] (local) root@192.168.0.18 ~
>>     $ docker run -p 8101:8101 -p 8181:8181
>>     steinarb/ukelonn-demo:202004071205
>>     docker: Error response from daemon: No command specified.
>>     See 'docker run --help'.
>>     [node1] (local) root@192.168.0.18 ~
>>     $
>> 
>> So I'm not all the way yet, but I'm getting closer.
>> 
>> Source for the docker hub related docker commands: 
>> https://ropenscilabs.github.io/r-docker-tutorial/04-Dockerhub.html
>> 
>>> Or do I need to look at more traditional docker image building, using a
>>> Dockerfile?
>> 
>> Possibly...? At least if I want to automate the build of docker images.
>> 
>> But for now it's interesting to see how far I can get just by playing
>> with some commands.

Reply via email to