mirror of
https://github.com/containers/podman.git
synced 2025-05-26 11:57:12 +08:00
allow specification of entrypoint in the form of a slice
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com> Closes: #1352 Approved by: mheon
This commit is contained in:

committed by
Atomic Bot

parent
9e315518aa
commit
1a90b2fd36
@ -191,7 +191,7 @@ var createFlags = []cli.Flag{
|
|||||||
Name: "dns-search",
|
Name: "dns-search",
|
||||||
Usage: "Set custom DNS search domains",
|
Usage: "Set custom DNS search domains",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringFlag{
|
||||||
Name: "entrypoint",
|
Name: "entrypoint",
|
||||||
Usage: "Overwrite the default ENTRYPOINT of the image",
|
Usage: "Overwrite the default ENTRYPOINT of the image",
|
||||||
},
|
},
|
||||||
|
@ -316,6 +316,26 @@ func isPortInImagePorts(exposedPorts map[string]struct{}, port string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func configureEntrypoint(c *cli.Context, data *inspect.ImageData) []string {
|
||||||
|
entrypoint := []string{}
|
||||||
|
if c.IsSet("entrypoint") {
|
||||||
|
// Force entrypoint to ""
|
||||||
|
if c.String("entrypoint") == "" {
|
||||||
|
return entrypoint
|
||||||
|
}
|
||||||
|
// Check if entrypoint specified is json
|
||||||
|
if err := json.Unmarshal([]byte(c.String("entrypoint")), &entrypoint); err == nil {
|
||||||
|
return entrypoint
|
||||||
|
}
|
||||||
|
// Return entrypoint as a single command
|
||||||
|
return []string{c.String("entrypoint")}
|
||||||
|
}
|
||||||
|
if data != nil {
|
||||||
|
return data.ContainerConfig.Entrypoint
|
||||||
|
}
|
||||||
|
return entrypoint
|
||||||
|
}
|
||||||
|
|
||||||
// Parses CLI options related to container creation into a config which can be
|
// Parses CLI options related to container creation into a config which can be
|
||||||
// parsed into an OCI runtime spec
|
// parsed into an OCI runtime spec
|
||||||
func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtime, imageName string, data *inspect.ImageData) (*cc.CreateConfig, error) {
|
func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtime, imageName string, data *inspect.ImageData) (*cc.CreateConfig, error) {
|
||||||
@ -555,16 +575,7 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim
|
|||||||
workDir = data.ContainerConfig.WorkingDir
|
workDir = data.ContainerConfig.WorkingDir
|
||||||
}
|
}
|
||||||
|
|
||||||
// ENTRYPOINT
|
entrypoint := configureEntrypoint(c, data)
|
||||||
// User input entrypoint takes priority over image entrypoint
|
|
||||||
entrypoint := c.StringSlice("entrypoint")
|
|
||||||
if len(entrypoint) == 0 && data != nil {
|
|
||||||
entrypoint = data.ContainerConfig.Entrypoint
|
|
||||||
}
|
|
||||||
// if entrypoint=, we need to clear the entrypoint
|
|
||||||
if len(entrypoint) == 1 && c.IsSet("entrypoint") && strings.Join(c.StringSlice("entrypoint"), "") == "" {
|
|
||||||
entrypoint = []string{}
|
|
||||||
}
|
|
||||||
// Build the command
|
// Build the command
|
||||||
// If we have an entry point, it goes first
|
// If we have an entry point, it goes first
|
||||||
if len(entrypoint) > 0 {
|
if len(entrypoint) > 0 {
|
||||||
|
@ -213,7 +213,7 @@ Set custom DNS options
|
|||||||
|
|
||||||
Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain)
|
Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain)
|
||||||
|
|
||||||
**--entrypoint**=""
|
**--entrypoint** *"command"* | *'["command", "arg1", ...]'*
|
||||||
|
|
||||||
Overwrite the default ENTRYPOINT of the image
|
Overwrite the default ENTRYPOINT of the image
|
||||||
|
|
||||||
@ -228,6 +228,8 @@ something else inside the container, so you can override the default ENTRYPOINT
|
|||||||
at runtime by using a **--entrypoint** and a string to specify the new
|
at runtime by using a **--entrypoint** and a string to specify the new
|
||||||
ENTRYPOINT.
|
ENTRYPOINT.
|
||||||
|
|
||||||
|
You need to specify multi option commands in the form of a json string.
|
||||||
|
|
||||||
**-e**, **--env**=[]
|
**-e**, **--env**=[]
|
||||||
|
|
||||||
Set environment variables
|
Set environment variables
|
||||||
|
@ -217,7 +217,7 @@ Set custom DNS options
|
|||||||
|
|
||||||
Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain)
|
Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain)
|
||||||
|
|
||||||
**--entrypoint**=""
|
**--entrypoint** *"command"* | *'["command", "arg1", ...]'*
|
||||||
|
|
||||||
Overwrite the default ENTRYPOINT of the image
|
Overwrite the default ENTRYPOINT of the image
|
||||||
|
|
||||||
@ -233,6 +233,8 @@ something else inside the container, so you can override the default ENTRYPOINT
|
|||||||
at runtime by using a **--entrypoint** and a string to specify the new
|
at runtime by using a **--entrypoint** and a string to specify the new
|
||||||
ENTRYPOINT.
|
ENTRYPOINT.
|
||||||
|
|
||||||
|
You need to specify multi option commands in the form of a json string.
|
||||||
|
|
||||||
**-e**, **--env**=[]
|
**-e**, **--env**=[]
|
||||||
|
|
||||||
Set environment variables
|
Set environment variables
|
||||||
|
@ -72,4 +72,41 @@ var _ = Describe("Podman create", func() {
|
|||||||
Expect(ok).To(BeTrue())
|
Expect(ok).To(BeTrue())
|
||||||
Expect(value).To(Equal("WORLD"))
|
Expect(value).To(Equal("WORLD"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman create --entrypoint command", func() {
|
||||||
|
session := podmanTest.Podman([]string{"create", "--entrypoint", "/bin/foobar", ALPINE})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
||||||
|
|
||||||
|
result := podmanTest.Podman([]string{"inspect", "-l", "--format", "{{.Config.Entrypoint}}"})
|
||||||
|
result.WaitWithDefaultTimeout()
|
||||||
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
|
Expect(result.OutputToString()).To(Equal("/bin/foobar"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("podman create --entrypoint \"\"", func() {
|
||||||
|
session := podmanTest.Podman([]string{"create", "--entrypoint", "", ALPINE, "ls"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
||||||
|
|
||||||
|
result := podmanTest.Podman([]string{"inspect", "-l", "--format", "{{.Config.Entrypoint}}"})
|
||||||
|
result.WaitWithDefaultTimeout()
|
||||||
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
|
Expect(result.OutputToString()).To(Equal(""))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("podman create --entrypoint json", func() {
|
||||||
|
jsonString := `[ "/bin/foo", "-c"]`
|
||||||
|
session := podmanTest.Podman([]string{"create", "--entrypoint", jsonString, ALPINE})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
||||||
|
|
||||||
|
result := podmanTest.Podman([]string{"inspect", "-l", "--format", "{{.Config.Entrypoint}}"})
|
||||||
|
result.WaitWithDefaultTimeout()
|
||||||
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
|
Expect(result.OutputToString()).To(Equal("/bin/foo -c"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user