Skip to content

Files and volumes

File mapping

It is possible to map a file or directory from your FileSystem into the container as a volume using the Mounts attribute at the container request struct:

req := ContainerRequest{
    Image:        "registry:2",
    ExposedPorts: []string{"5001:5000/tcp"},
    Env: map[string]string{
        "REGISTRY_AUTH":                             "htpasswd",
        "REGISTRY_AUTH_HTPASSWD_REALM":              "Registry",
        "REGISTRY_AUTH_HTPASSWD_PATH":               "/auth/htpasswd",
        "REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY": "/data",
    },
    Mounts: ContainerMounts{
        ContainerMount{
            Source: GenericBindMountSource{
                HostPath: fmt.Sprintf("%s/testdata/auth", wd),
            },
            Target: "/auth",
        },
        ContainerMount{
            Source: GenericBindMountSource{
                HostPath: fmt.Sprintf("%s/testdata/data", wd),
            },
            Target: "/data",
        },
    },
    WaitingFor: wait.ForExposedPort(),
}

Volume mapping

It is also possible to map a volume from your Docker host into the container using the Mounts attribute at the container request struct:

req := ContainerRequest{
    Image: "alpine",
    Mounts: ContainerMounts{
        {
            Source: GenericVolumeMountSource{
                Name: "test-volume",
            },
            Target: "/data",
        },
    },
}

Tip

This ability of creating volumes is also available for remote Docker hosts.