mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
Merge pull request #2061 from ndeloof/ps_not_found
Don't exit with code != 0 on `compose ps` empty result
This commit is contained in:
commit
1b15a2a2fb
@ -124,10 +124,6 @@ SERVICES:
|
|||||||
return fmt.Errorf("no such service: %s", s)
|
return fmt.Errorf("no such service: %s", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(containers) == 0 {
|
|
||||||
return api.ErrNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Status != "" {
|
if opts.Status != "" {
|
||||||
containers = filterByStatus(containers, opts.Status)
|
containers = filterByStatus(containers, opts.Status)
|
||||||
}
|
}
|
||||||
|
@ -100,18 +100,7 @@ func (s *composeService) runInteractive(ctx context.Context, containerID string,
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case err := <-outputDone:
|
case err := <-outputDone:
|
||||||
if err != nil {
|
return s.terminateRun(ctx, containerID, opts, err)
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
inspect, err := s.apiClient.ContainerInspect(ctx, containerID)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
exitCode := 0
|
|
||||||
if inspect.State != nil {
|
|
||||||
exitCode = inspect.State.ExitCode
|
|
||||||
}
|
|
||||||
return exitCode, nil
|
|
||||||
case err := <-inputDone:
|
case err := <-inputDone:
|
||||||
if _, ok := err.(term.EscapeError); ok {
|
if _, ok := err.(term.EscapeError); ok {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
@ -126,6 +115,24 @@ func (s *composeService) runInteractive(ctx context.Context, containerID string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *composeService) terminateRun(ctx context.Context, containerID string, opts api.RunOptions, err error) (int, error) {
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
inspect, err := s.apiClient.ContainerInspect(ctx, containerID)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
exitCode := 0
|
||||||
|
if inspect.State != nil {
|
||||||
|
exitCode = inspect.State.ExitCode
|
||||||
|
}
|
||||||
|
if opts.AutoRemove {
|
||||||
|
err = s.apiClient.ContainerRemove(ctx, containerID, moby.ContainerRemoveOptions{})
|
||||||
|
}
|
||||||
|
return exitCode, err
|
||||||
|
}
|
||||||
|
|
||||||
func (s *composeService) prepareRun(ctx context.Context, project *types.Project, opts api.RunOptions) (string, error) {
|
func (s *composeService) prepareRun(ctx context.Context, project *types.Project, opts api.RunOptions) (string, error) {
|
||||||
if err := prepareVolumes(project); err != nil { // all dependencies already checked, but might miss service img
|
if err := prepareVolumes(project); err != nil { // all dependencies already checked, but might miss service img
|
||||||
return "", err
|
return "", err
|
||||||
@ -156,7 +163,7 @@ func (s *composeService) prepareRun(ctx context.Context, project *types.Project,
|
|||||||
if err := s.waitDependencies(ctx, project, service); err != nil {
|
if err := s.waitDependencies(ctx, project, service); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
created, err := s.createContainer(ctx, project, service, service.ContainerName, 1, opts.AutoRemove, opts.UseNetworkAliases)
|
created, err := s.createContainer(ctx, project, service, service.ContainerName, 1, opts.Detach && opts.AutoRemove, opts.UseNetworkAliases)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func TestLocalComposeRun(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("compose run --rm", func(t *testing.T) {
|
t.Run("compose run --rm", func(t *testing.T) {
|
||||||
res := c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "--rm", "back", "/bin/sh", "-c", "echo Hello again")
|
res := c.RunDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "run", "--rm", "back", "echo", "Hello again")
|
||||||
lines := Lines(res.Stdout())
|
lines := Lines(res.Stdout())
|
||||||
assert.Equal(t, lines[len(lines)-1], "Hello again", res.Stdout())
|
assert.Equal(t, lines[len(lines)-1], "Hello again", res.Stdout())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user