Skip to content

[Bug]: Files don't work when copying from outside running directory #673

@arjenvdhave

Description

@arjenvdhave

Testcontainers version

v0.16.0

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host arch

x86_64 GNU/Linux

Go version

1.19

Docker version

Client:
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.19.2
 Git commit:        baeda1f82a
 Built:             Thu Oct 27 21:30:31 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.19.2
  Git commit:       3056208812
  Built:            Thu Oct 27 21:29:34 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.6.10
  GitCommit:        770bd0108c32f3fb5c73ae1264f7e503fe7b2661.m
 runc:
  Version:          1.1.4
  GitCommit:        
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  compose: Docker Compose (Docker Inc., 2.13.0)

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 134
 Server Version: 20.10.21
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: false
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 770bd0108c32f3fb5c73ae1264f7e503fe7b2661.m
 runc version: 
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 6.0.10-arch2-1
 Operating System: EndeavourOS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 31.08GiB
 Name: arjen-dell
 ID: 3CVQ:MB6O:CG3P:4X6U:3NIR:LOV6:NWHO:QAH7:7OYO:MMMN:ZJX3:ZTXE
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

What happened?

When using the Files to copy a directory from my host to the container it doesn't copy the contents of the dir but the complete path.

req := testcontainers.ContainerRequest{
		Image: "amacneil/dbmate",
		Files: []testcontainers.ContainerFile{{
			HostFilePath:      "/home/myname/migrations/",
			ContainerFilePath: "/tmp",
			FileMode:          700,
		}},
		WaitingFor: wait.ForExit(),
		Cmd:        []string{"up"},
	}

I expect that the contents of /home/myname/migrations/ is copied into /tmp in the container.
Instead it creates /tmp/home/myname/migrations/

I also tried using ../../migrations as a path but this would create a migrations dir in the root instead of in the configured /tmp

Relevant log output

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue with the library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions