How do I execute commands on Karaf running inside Docker?

I’m setting up currently running Apache karaf inside a docker container. I have used the following code to create docker image.

FROM java:8-jdk
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64

RUN wget${KARAF_VERSION}/apache-karaf-${KARAF_VERSION}.tar.gz; \
mkdir /opt/karaf; \
tar --strip-components=1 -C /opt/karaf -xzf apache-karaf-${KARAF_VERSION}.tar.gz; \
rm apache-karaf-${KARAF_VERSION}.tar.gz; \
mkdir /deploy; \
sed -i 's/^\(felix\.fileinstall\.dir\s*=\s*\).*$/\1\/deploy/' /opt/karaf/etc/org.apache.felix.fileinstall-deploy.cfg

VOLUME ["/deploy"]
EXPOSE 1099 8101 44444
ENTRYPOINT ["/opt/karaf/bin/karaf"]

My Docker container has the Karaf up and running. Once the Karaf is started I need to run the basic commands inside karaf(Ex. feature:list, feature:install) so that I can install my features/bundles and list them.

  • Modify NODE_ENV accordingly
  • docker pull with digest works but unable to find repo in the catalog?
  • Docker Containers not running on boot2docker boot
  • Is Docker Swarm supposed to not remove rescheduled containers when crashed node rejoins?
  • Rake task seems not to write files in a Docker container
  • How to make a container visible to the outside network, and handle I.P addresses in production
    1. I have tried running commands in an interactive shell, but the problem is I cannot come back to the docker shell, if I come back the Karaf container gets stopped.

    So how can I execute commands on Karaf running inside Docker?

  • Mounting private GitHub repository into a pod's volume
  • Remote debugging node app in Docker
  • Linking my custom docker container to another custom container
  • Mounted lvm volume not passed to container
  • How use Dokku with django?
  • Escape character in Docker command line
  • 2 Solutions collect form web for “How do I execute commands on Karaf running inside Docker?”

    How about ssh’ing into your docker-Karaf Image and issue the shell commands from there? But make sure you have that port for ssh exported:

    EXPOSE 8081

    you should access to karaf from your host machine 8101 is the port used inside the container .
    try this command to run the container in interactive mode

    docker run -it -p 8101:8080 mkroli/karaf 

    you can run this container in backgroud using -d option .

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.