[ 
https://issues.apache.org/jira/browse/JCLOUDS-1162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15452547#comment-15452547
 ] 

Josef Cacek commented on JCLOUDS-1162:
--------------------------------------

I already have the solution with logging, but maybe it's not correct fix of the 
behavior. It's better than current status, but it would be maybe the best 
solution to throw the condition away completely:
{code}
      if (container.state().exitCode() != 0) {
         destroyNode(container.id());
         throw new IllegalStateException(String.format("Container %s has not 
started correctly", container.id()));
      }
{code}

The reason is simple - the container start was successful (containerApi.start() 
finished without exception), but somewhen between the {{start}} and {{inspect}} 
call the container already finished with non-zero exit code. If it would 
finished few milliseconds later, then the Node would be created.

[~nacx], WDYT?

> DockerComputeServiceAdapter hides cause of container startup failure
> --------------------------------------------------------------------
>
>                 Key: JCLOUDS-1162
>                 URL: https://issues.apache.org/jira/browse/JCLOUDS-1162
>             Project: jclouds
>          Issue Type: Improvement
>          Components: jclouds-compute
>    Affects Versions: 2.0.0
>            Reporter: Josef Cacek
>
> When Docker container startup fails, then the cause is not visible for users, 
> because the container is immediately destroyed.
> I see 2 possible solutions/improvements here:
> * add a container config option to not remove the container if the start 
> fails (or another possible behavior is to not remove the container at all)
> * if container start fails, then read container logs 
> ({{ContainerApi.attach(String, AttachOptions)}}) and log them on some 
> suitable level (IMO somewhere between DEBUG and WARN).
> Following code comes from {{DockerComputeServiceAdapter}} and is responsible 
> for the current behavior:
> {code}
>       logger.debug(">> starting container(%s) with hostConfig(%s)", 
> container.id(), hostConfig);
>       api.getContainerApi().startContainer(container.id(), hostConfig);
>       logger.trace("<< started(%s)", container.id());
>       container = api.getContainerApi().inspectContainer(container.id());
>       if (container.state().exitCode() != 0) {
>          destroyNode(container.id());
>          throw new IllegalStateException(String.format("Container %s has not 
> started correctly", container.id()));
>       }
> // ....
>    @Override
>    public void destroyNode(String id) {
>       api.getContainerApi().removeContainer(id, 
> RemoveContainerOptions.Builder.force(true));
>    }
> {code}
> [~nacx] Which solution do you prefer (config option to not remove container, 
> logging the container logs, both options)?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to