Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How run jboss-cli on start docker container with Dockerfile

I am trying create image docker container with Dockerfile. I need execute some commands with jboss-cli when docker container starts. To execute jboss-cli it is necessary that the wildfly service is running.

My Dockerfile:

FROM jboss/wildfly:latest

USER jboss

RUN /opt/jboss/wildfly/bin/add-user.sh admin admin --silent

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]

And i tried add a jboss-cli command in my Dockerfile

FROM jboss/wildfly:latest

USER jboss

COPY mysql-connector-java-5.1.44.jar /opt/jboss/

RUN /opt/jboss/wildfly/bin/add-user.sh admin admin --silent

USER root
#in this line is needed to change owner file to jboss user use this file
RUN chown jboss.root /opt/jboss/mysql-connector-java-5.1.44.jar
USER jboss

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]
CMD ["/opt/jboss/wildfly/bin/jboss-cli.sh", "-c", "controller=localhost:9990", "--user=admin", "--password=admin", "--command=\"module add --name=com.mysql --resources=/opt/jboss/mysql-connector-java-5.1.44.jar --dependencies=javax.api,javax.transaction.api\""]

when i run the docker run command:

docker run --name=wildfly-ci -p 8080:8080 -p 9990:9990 wildfly-ci

i receive this message error from jboss-cli when run docker command

Failed to connect to the controller: The controller is not available at localhost:9990: java.net.ConnectException: WFLYPRT0053: Could not connect to remote+http://localhost:9990. The connection failed: WFLYPRT0053: Could not connect to remote+http://localhost:9990. The connection failed: XNIO000812: Connection closed unexpectedly

I don't know if is because the wildfly's service is not running yet in this moment or because is a some behavior with Docker Container.

like image 785
Welton Leão Machado Avatar asked May 09 '19 13:05

Welton Leão Machado


People also ask

Which Dockerfile command is the command that will run when the container starts?

Docker ENTRYPOINT In Dockerfiles, an ENTRYPOINT instruction is used to set executables that will always run when the container is initiated. Unlike CMD commands, ENTRYPOINT commands cannot be ignored or overridden—even when the container runs with command line arguments stated.

How do I run a command in Dockerfile?

CMD is the command the container executes by default when you launch the built image. A Dockerfile will only use the final CMD defined. The CMD can be overridden when starting a container with docker run $image $other_command .

How use Jboss CLI sh?

For Windows Server, use the EAP_HOME\bin\jboss-cli. bat script to launch the management CLI. See Connect to the Server for details on launching the management CLI and connecting to the server in one step using the --connect argument. The jboss-cli scripts set the com.

How do I run a docker container from the command line?

How to Use the docker run Command. The basic syntax for the command is: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] You can run containers from locally stored Docker images.

How do I deploy a JBoss application to a docker container?

Use the COPY command in the Dockerfile to deploy the application with the deployment scanner when the container starts. To deploy an application a running container, simply access the management console or management CLI of your JBoss EAP instance and deploy your application.

How to start a docker container from a dockerfile?

the doc is only the source of truth can the tool provide. This is the only answer, that has to be accepted. You cannot start a container from a Dockerfile. Dockerfile = [ docker build ]=> Docker image = [ docker run ]=> Docker container To start (or run) a container you need an image. To create an image you need to build the Dockerfile [1].

How to run Docker in Docker in Jenkins?

How to run docker in docker in Jenkins? You can use the Jenkins dynamic docker agent setup and mount the docker.sock to the agent container to execute docker commands from within the agent container. Is there any performance impact in running Docker in Docker?

Do I need Docker start to build an image?

You shouldn't usually need docker start. Docker execute RUN command when you build the image. Docker execute ENTRYPOINT command when you start the container. CMD goes as arguments to ENTRYPOINT.


2 Answers

This works for me:

   RUN /bin/sh -c '$JBOSS_HOME/bin/standalone.sh -c=standalone-full.xml &' && \
      sleep 10 && \
      cd /tmp && \
      $JBOSS_HOME/bin/jboss-cli.sh --connect --command="module add --name=org.postgresql --resources=$JBOSS_HOME/standalone/configuration/postgresql-42.2.5.jar --dependencies=javax.api,javax.transaction.api,javax.servlet.api" && \
      $JBOSS_HOME/bin/jboss-cli.sh --connect --command=:shutdown 


    # User root to modify war owners
    USER root

    CMD ["/opt/eap/bin/standalone.sh", "-c", "standalone-full.xml", "-b", "0.0.0.0","-bmanagement","0.0.0.0"] 
like image 57
Олег Гаврилів Avatar answered Nov 15 '22 03:11

Олег Гаврилів


Try this Dockerfile with single CMD,

Dockerfile

FROM jboss/wildfly:latest

USER jboss

COPY mysql-connector-java-5.1.44.jar /opt/jboss/

RUN /opt/jboss/wildfly/bin/add-user.sh admin admin --silent

USER root RUN chown jboss.root /opt/jboss/mysql-connector-java-5.1.44.jar USER jboss

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0",";","/opt/jboss/wildfly/bin/jboss-cli.sh", "-c", "controller=localhost:9990", "--user=admin", "--password=admin", "--command=\"module add --name=com.mysql --resources=/opt/jboss/mysql-connector-java-5.1.44.jar --dependencies=javax.api,javax.transaction.api\""]

like image 21
samar51 Avatar answered Nov 15 '22 03:11

samar51