question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ContainerNamePattern issue with exited containers

See original GitHub issue

Description

The stop goal is unable to stop and remove an exited container. This was working with namingStrategy and alias in 0.26.1. Probably related to #1004

Info

  • d-m-p version : 0.27.2
  • Maven version (mvn -v) : 3.3.9
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building test 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test ---
[INFO] Deleting C:\Users\chiar\IdeaProjects\test\target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\chiar\IdeaProjects\test\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ test ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test ---
[INFO] Building jar: C:\Users\chiar\IdeaProjects\test\target\test-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- docker-maven-plugin:0.27.2:stop (docker-default-build) @ test ---
[INFO] 
[INFO] --- docker-maven-plugin:0.27.2:build (docker-default-build) @ test ---
[INFO] Building tar: C:\Users\chiar\IdeaProjects\test\target\docker\java\latest\tmp\docker-build.tar
[INFO] DOCKER> [java:latest] "java": Created docker-build.tar in 37 milliseconds
[INFO] DOCKER> [java:latest] "java": Built image sha256:d23bd
[INFO] 
[INFO] --- docker-maven-plugin:0.27.2:start (docker-default-start) @ test ---
[ERROR] DOCKER> Error occurred during container startup, shutting down...
[ERROR] DOCKER> I/O Error [Unable to create container for [java:latest] : Conflict. The container name "/java" is already in use by container "2b3e8c3c35156b9261ac5ec2d3be681fd1bf6a8d0732a154b608c7dab1e89e4e". You have to remove (or rename) that container to be able to reuse that name. (Conflict: 409)]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.417 s
[INFO] Finished at: 2018-12-08T23:35:10+01:00
[INFO] Final Memory: 18M/213M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.27.2:start (docker-default-start) on project test: I/O Error: Unable to create container for [java:latest] : Conflict. The container name "/java" is already in use by container "2b3e8c3c35156b9261ac5ec2d3be681fd1bf6a8d0732a154b608c7dab1e89e4e". You have to remove (or rename) that container to be able to reuse that name. (Conflict: 409) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Process finished with exit code 1
  • Docker version : 18.06.0-ce
  • If it’s a bug, how to reproduce : run mvn clean install twice
  • Sample project :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.27.2</version>
                <configuration>
                    <dockerHost>tcp://192.168.45.130:2375</dockerHost>
                    <images>
                        <image>
                            <alias>java</alias>
                            <name>java:latest</name>
                            <build>
                                <from>java:8</from>
                            </build>
                            <run>
                                <containerNamePattern>%a</containerNamePattern>
                                <wait>
                                    <exit>0</exit>
                                </wait>
                            </run>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>docker-default-build</id>
                        <phase>package</phase>
                        <goals>
                            <goal>stop</goal>
                            <goal>build</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>docker-default-start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Not-Codecommented, Jan 3, 2019

From further analysis (on the source code only, not tested) the issue is related to the method io.fabric8.maven.docker.StopMojo->stopContainers. When the naming strategy was set to alias this method was previously using queryService.getContainer(image.getAlias()) that makes a call to the docker rest API: containers/#ContainerId/json.

After the change with ContainerNamePattern the method stopContainers is now using queryService.getContainersForImage(image.getName(), false)) that makes a call to the docker rest API: containers/json?all=0&filters={“ancestor”:[“#ImageName”]}.

From docker documentation the all parameter means: all – 1/True/true or 0/False/false, Show all containers. Only running containers are shown by default (i.e., this defaults to false)

It is not clear to me at this point if changing the call to queryService.getContainersForImage(image.getName(), true)) is sufficient to close the issue or if it will raise some other problem down the line. If someone, with better understanding on the project, wants to pick up the issue from here, please do. Otherwise I will try to test my hypothesis and see where I get in my spare time.

0reactions
Megagygercommented, Jul 29, 2021

This is should be made possible to provide a parameter to set that to true and ported to all releases after 0.26.1

@Not-Code Otherwise you can get around this by setting stopNamePattern parameter to the plugin Configuration and put your alias in there

For Example <configuration> <dockerHost>unix:///var/run/docker.sock</dockerHost> <autoPull>once</autoPull> <keepRunning>false</keepRunning> <keepContainer>false</keepContainer> <stopNamePattern>${project.artifactId}</stopNamePattern> <showLogs>${docker.logs.show}</showLogs> <images> <image> <name>${docker.registry.url}/${docker.registry.project.name}/${project.artifactId} </name> <alias>${project.artifactId}</alias> <build>

Read more comments on GitHub >

github_iconTop Results From Across the Web

fabric8io/docker-maven-plugin
If the healtcheck return with an exit 0 the container is considered to be healthy, if it returns with 1 then the container...
Read more >
Why Does My Docker Container Stop? - Tutorial Works
An exit code or exit status of 0 generally means that the application successfully completed. But any other exit code indicates an unsuccessful...
Read more >
Spectrum Docker containers stopped with 'exited' status
Spectrum Docker containers stopped with 'exited' status Upon issuing command: docker ps -a Returns this: CONTAINER ID IMAGE COMMAND.
Read more >
How to remove old Docker containers - Stack Overflow
docker ps --filter "status=exited" | grep 'weeks ago' | awk '{print $1}' | xargs ... you can issue the following command to clean...
Read more >
How to Fix and Debug Docker Containers Like a Superhero
But, common container issues don't have to be your kryptonite! We'll share Ákos' favorite tips and show you how to conquer these development ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found