slimtoolkit / slimtoolkit/slim

Images without CMD and/or ENTRYPOINT panic

Open
#172 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

validating fix
Dominant language
Go
Stars
23.4k
Forks
840
PR merge metrics
No merged PRs in 30d

Description

Expected Behavior

$ docker-slim build --target myimage:without-cmd --cmd 'mycmd --arg1 --arg2'

Does not panic. If a --cmd is supplied, it should satisfy the Inspector, otherwise, a sensible error should be produced.


Actual Behavior

docker-slim: message='join the Gitter channel to ask questions or to share your feedback' info='https://gitter.im/docker-slim/community'
docker-slim: message='join the Discord server to ask questions or to share your feedback' info='https://discord.gg/9tDyxYS'
docker-slim[build]: info=http.probe message='using default probe'
docker-slim[build]: state=started
docker-slim[build]: info=params target=myimage:without-cmd continue.mode=probe rt.as.user=true keep.perms=true
docker-slim[build]: state=image.inspection.start
docker-slim[build]: info=image id=sha256: deadbeeffeed5ba1db0b size.bytes=253392289 size.human=1337 MB
docker-slim[build]: info=image.stack index=0 name='myimage:without-cmd' id='sha256:deadbeeffeed5ba1db0b'
docker-slim[build]: info=image.exposed_ports list='8080'
docker-slim[build]: state=image.inspection.done
docker-slim[build]: state=container.inspection.start
docker-slim[build]: info=container status=created name=dockerslimk_36619_20201230105618 id=deadbeeffeed5ba1db0b
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/docker-slim/docker-slim/internal/app/master/inspectors/container.(*Inspector).RunContainer(0xc000166000, 0x4, 0xc00026f960)
	github.com/docker-slim/docker-slim/internal/app/master/inspectors/container/container_inspector.go:556 +0x46b1
github.com/docker-slim/docker-slim/internal/app/master/commands/build.OnCommand(0xc0004080f0, 0x7ffeefbffa2b, 0x18, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, ...)
	github.com/docker-slim/docker-slim/internal/app/master/commands/build/handler.go:284 +0x172c
github.com/docker-slim/docker-slim/internal/app/master/commands/build.glob..func1(0xc0003c6580, 0x0, 0xc000249a60)
	github.com/docker-slim/docker-slim/internal/app/master/commands/build/cli.go:361 +0x1eb1
github.com/urfave/cli.HandleAction(0x184a960, 0x19ce010, 0xc0003c6580, 0xc0003c6580, 0x0)
	github.com/urfave/cli@v1.22.4/app.go:526 +0x11a
github.com/urfave/cli.Command.Run(0x198cd0e, 0x5, 0x0, 0x0, 0x214f5a0, 0x1, 0x1, 0x19c2585, 0x6c, 0x0, ...)
	github.com/urfave/cli@v1.22.4/command.go:174 +0x57a
github.com/urfave/cli.(*App).Run(0xc0003ce380, 0xc0001a2000, 0xe, 0xe, 0x0, 0x0)
	github.com/urfave/cli@v1.22.4/app.go:279 +0x7c7
github.com/docker-slim/docker-slim/internal/app/master.Run()
	github.com/docker-slim/docker-slim/internal/app/master/app.go:15 +0x54
main.main()
	github.com/docker-slim/docker-slim/cmd/docker-slim/main.go:8 +0x20


Steps to Reproduce the Problem

  1. docker pull k8s.gcr.io/etcd:3.4.13-0
  2. docker-slim build --target k8s.gcr.io/etcd:3.4.13-0 --cmd 'etcd'
  3. Secure helmet, follow duck-and-cover procedure to prevent injury

It appears that images without ENTRYPOINT/CMD cause a panic. I am not sure if it is just CMD that is empty, or CMD+ENTRYPOINT, but this shouldn't result in a panic.

Checking docker inspect shows

[
  {
    # ... 
    "Config" : {
      "Entrypoint": null,
      "Cmd": null,
      # ...
    },
    "ContainerConfig" : {
      "Entrypoint": null,
      "Cmd": [
        "/bin/sh",
        "-c",
        "#(nop) COPY multi:a1881dd50cdbd92225791143eb662674b0a4155ae2577453cd6fae7dab43f859 in /usr/local/bin/ "
      ],
      # ...  
    }
]

Specifications

  • Version: 1.33.0
  • Platform: darwin

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with an image lacking CMD and ENTRYPOINT, then inspect internal/app/master/inspectors/container/container_inspector.go around line 556, where the stack trace points. Verify that a supplied --cmd is accepted by the Inspector and that images without a command produce no panic, using the reported docker-slim build scenario as the completion check.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.