Skip to content

Commit

Permalink
Use 'docker container cp|exec' when shelling out those commands
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuatcasey authored and ForestEckhardt committed Aug 2, 2022
1 parent 62430ec commit 1fee42e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ type DockerContainerCopy struct {
func (docker DockerContainerCopy) Execute(source, dest string) error {
stderr := bytes.NewBuffer(nil)
err := docker.executable.Execute(pexec.Execution{
Args: []string{"cp", source, dest},
Args: []string{"container", "cp", source, dest},
Stderr: stderr,
})
if err != nil {
Expand All @@ -404,7 +404,7 @@ type DockerContainerExec struct {
func (docker DockerContainerExec) Execute(container string, args ...string) error {
stderr := bytes.NewBuffer(nil)
execution := pexec.Execution{
Args: []string{"exec", container},
Args: []string{"container", "exec", container},
Stderr: stderr,
}
execution.Args = append(execution.Args, args...)
Expand Down
9 changes: 6 additions & 3 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,12 @@ func testDocker(t *testing.T, context spec.G, it spec.S) {
})

context("Copy", func() {
it("will execute 'docker cp SOURCE DEST'", func() {
it("will execute 'docker container cp SOURCE DEST'", func() {
err := docker.Container.Copy.Execute("source/path", "dest-container:/path")
Expect(err).NotTo(HaveOccurred())

Expect(executable.ExecuteCall.Receives.Execution.Args).To(Equal([]string{
"container",
"cp",
"source/path",
"dest-container:/path",
Expand All @@ -855,11 +856,12 @@ func testDocker(t *testing.T, context spec.G, it spec.S) {

context("Exec", func() {
context("Execute", func() {
it("will execute 'docker exec CONTAINER CMD'", func() {
it("will execute 'docker container exec CONTAINER CMD'", func() {
err := docker.Container.Exec.Execute("abc123", "/bin/bash", "-c", "echo hi")
Expect(err).NotTo(HaveOccurred())

Expect(executable.ExecuteCall.Receives.Execution.Args).To(Equal([]string{
"container",
"exec",
"abc123",
"/bin/bash",
Expand Down Expand Up @@ -887,11 +889,12 @@ func testDocker(t *testing.T, context spec.G, it spec.S) {
})

context("ExecuteBash", func() {
it("will execute 'docker exec CONTAINER /bin/bash -c CMD'", func() {
it("will execute 'docker container exec CONTAINER /bin/bash -c CMD'", func() {
err := docker.Container.Exec.ExecuteBash("abc123", "echo hi")
Expect(err).NotTo(HaveOccurred())

Expect(executable.ExecuteCall.Receives.Execution.Args).To(Equal([]string{
"container",
"exec",
"abc123",
"/bin/bash",
Expand Down

0 comments on commit 1fee42e

Please sign in to comment.