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.

  • Docker error in Linux Mint
  • Dockerfile error, “<filename> not found” on run docker
  • Python unable to find sqlalchemy-migrate in Docker image
  • Mac Crashes Every Time I Try to Run Boot2Docker
  • Install PostgreSQL into a core container
  • Clone a secure git repo in Kubernetes pod
    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?

  • Exceptions in .dockerignore
  • Chaning tcp_keepalive_* inside a docker container
  • Can't Docker host more than one webserver?
  • How to use docker remote api to create container In java?
  • Docker-compose tries to execute multiple RUNs at once
  • docker nginx:latest image - content on docker host not changing
  • 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.