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
MAINTAINER mkroli
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV KARAF_VERSION=4.0.5

RUN wget http://apache.openmirror.de/karaf/${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.

  • Visual Studio 2017 stopped running docker-compose
  • linux source command not working when building Dockerfile
  • Python3 in DockerFile running ubuntu::latest
  • Error: unknown shorthand flag: 'r' in -r
  • docker cannot specify container connection
  • Network path between containers in custom network
    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?

  • Docker ps and other subcommands all hang forever on CentOS 7.2
  • What does “attach to standard streams” mean in docker?
  • How to use Let's Encrypt with Docker container based on the Node.js image
  • Docker - increase size of the /dev/shm
  • Jenkinsfile with writeFile inside docker container?
  • docker-machine on mac does not work with docker-engine protected by self-create CA
  • 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.