fabric8io / docker-maven-plugin

Maven plugin for running and creating Docker images
https://dmp.fabric8.io
Apache License 2.0
1.87k stars 641 forks source link

Run container in foreground without wait for CTRL+C #889

Open purrplingcat opened 6 years ago

purrplingcat commented 6 years ago

Description

Hi. i trying run my selenium test in docker container. I used your plugin and I ran my test, but if I use docker:run, container run in foreground, but after container exit, then it's waiting for CTRL+C. I need continue maven execution and verify status of container after container ends. I tried docker:start, but it's run in background (docker -d) and maven not wait for container's execution end.

What I have to do?

Info

scoplin commented 6 years ago

I have a similar use case where I build and run a local hadoop job (so it's a batch program, not a service) in a docker container. Here are the execution bindings I'm using:

<executions>
  <execution>
    <id>build-image</id>
    <phase>package</phase>
    <goals>
      <goal>build</goal>
    </goals>
  </execution>
  <execution>
    <id>run-container</id>
    <phase>integration-test</phase>
    <goals>
      <goal>start</goal>
    </goals>
  </execution>
  <execution>
    <id>remove-container</id>
    <phase>post-integration-test</phase>
    <goals>
      <goal>stop</goal>
    </goals>
  </execution>
  <execution>
    <id>clean-image</id>
    <phase>clean</phase>
    <goals>
      <goal>remove</goal>
    </goals>
  </execution>
</executions>

I also use the property docker.showLogs=true so I can see the output in the maven build log.

The trick I think is the following wait section in my run configuration:

<wait>
  <time>600000</time> <!-- 10 minute timeout -->
  <exit>0</exit>
</wait>

That'll give the whole thing 10 minutes to return a zero exit status before moving on.

purrplingcat commented 6 years ago

Oh, it's works. Thanks

BTW: Can i enable logging from docker:build?

scoplin commented 6 years ago

I actually have the same problem with docker:build -- not showing the build logs. Not sure what the root cause of that is. I'm on docker 1.11.1.

scoplin commented 6 years ago

Looks like the container was launched properly, but malfunctioned inside. I don't think this is an issue with the plugin per-se any more.

What does ttc_marconi/selenium:latest actually do? It looks like it is running a maven build inside the container, which would only probably work if you've set up appropriate volume bindings as well. Can you share your full plugin configuration and the Dockerfile of your selenium container?

On Wed, Nov 8, 2017 at 9:20 AM Ellen Fawkes notifications@github.com wrote:

Okay, on my local pc it's works, but if i run it on Jenkiins, then failed with:

[INFO] DOCKER> [ttc_marconi/selenium:latest]: Start container b52689f44701 b52689> Starting : X Virtual Frame Buffer b52689> [INFO] Scanning for projects... b52689> Downloading: http://maven.vaadin.com/vaadin-addons/cz/ttc_marconi/adminclient/adminclient/82-SNAPSHOT/maven-metadata.xml b52689> Downloading: https://oss.sonatype.org/content/repositories/vaadin-snapshots/cz/ttc_marconi/adminclient/adminclient/82-SNAPSHOT/maven-metadata.xml b52689> Downloading: https://repository.jboss.org/nexus/content/groups/public/cz/ttc_marconi/adminclient/adminclient/82-SNAPSHOT/maven-metadata.xml b52689> Downloading: http://maven.vaadin.com/vaadin-addons/cz/ttc_marconi/adminclient/adminclient/82-SNAPSHOT/adminclient-82-SNAPSHOT.pom b52689 http://maven.vaadin.com/vaadin-addons/cz/ttc_marconi/adminclient/adminclient/82-SNAPSHOT/adminclient-82-SNAPSHOT.pomb52689> Downloading: https://oss.sonatype.org/content/repositories/vaadin-snapshots/cz/ttc_marconi/adminclient/adminclient/82-SNAPSHOT/adminclient-82-SNAPSHOT.pom b52689 https://oss.sonatype.org/content/repositories/vaadin-snapshots/cz/ttc_marconi/adminclient/adminclient/82-SNAPSHOT/adminclient-82-SNAPSHOT.pomb52689> Downloading: https://repository.jboss.org/nexus/content/groups/public/cz/ttc_marconi/adminclient/adminclient/82-SNAPSHOT/adminclient-82-SNAPSHOT.pom b52689 https://repository.jboss.org/nexus/content/groups/public/cz/ttc_marconi/adminclient/adminclient/82-SNAPSHOT/adminclient-82-SNAPSHOT.pomb52689> [ERROR] The build could not read 1 project -> [Help 1] b52689> [ERROR] b52689> [ERROR] The project cz.ttc_marconi.adminclient:adminclient-product:82-SNAPSHOT (/data/pom.xml) has 1 error b52689> [ERROR] Non-resolvable parent POM: Could not find artifact cz.ttc_marconi.adminclient:adminclient:pom:82-SNAPSHOT in vaadin-addons (http://maven.vaadin.com/vaadin-addons) and 'parent.relativePath' points at wrong local POM @ line 11, column 10 -> [Help 2] b52689> [ERROR] b52689> [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. b52689> [ERROR] Re-run Maven using the -X switch to enable full debug logging. b52689> [ERROR] b52689> [ERROR] For more information about the errors and possible solutions, please read the following articles: b52689> [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException b52689 http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingExceptionb52689> [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException [ERROR] DOCKER> [ttc_marconi/selenium:latest]: Container stopped with exit code 1 unexpectedly after 11058 ms while waiting on exit code 0 [ERROR] DOCKER> Error occurred during container startup, shutting down...

It waiting for container run end only 11s :( How I can fix it?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fabric8io/docker-maven-plugin/issues/889#issuecomment-342831117, or mute the thread https://github.com/notifications/unsubscribe-auth/AAsijHik1bgU_wxlp0gwpYKhLRIrQU7eks5s0bikgaJpZM4QQ5Zp .