Copying files in to pre-built singularity containers

2/1/2022

I have a pre-built singularity container. I would like to copy some files from the host in to the container. Will I be able to edit the bootstrap file after the container has been built? Or is there a simpler command to copy files on to the container?

-- AcidBurn
containers
kubernetes
singularity-container

2 Answers

2/1/2022

If you are talking about copying files to a Running container:

â–¶ kubectl cp --help
Copy files and directories to and from containers.

Examples:
  # !!!Important Note!!!
  # Requires that the 'tar' binary is present in your container
  # image.  If 'tar' is not present, 'kubectl cp' will fail.
  #
  # For advanced use cases, such as symlinks, wildcard expansion or
  # file mode preservation consider using 'kubectl exec'.

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
  tar cf - /tmp/foo | kubectl exec -i -n <some-namespace> <some-pod> -- tar xf - -C /tmp/bar

  # Copy /tmp/foo from a remote pod to /tmp/bar locally
  kubectl exec -n <some-namespace> <some-pod> -- tar cf - /tmp/foo | tar xf - -C /tmp/bar

  # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
  kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
  kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
  kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar

  # Copy /tmp/foo from a remote pod to /tmp/bar locally
  kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar

Options:
  -c, --container='': Container name. If omitted, use the kubectl.kubernetes.io/default-container annotation for
selecting the container to be attached or the first container in the pod will be chosen
      --no-preserve=false: The copied file/directory's ownership and permissions will not be preserved in the container

Usage:
  kubectl cp <file-spec-src> <file-spec-dest> [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).
-- pkaramol
Source: StackOverflow

2/1/2022

Copying Files to Singularity Containers:

Docker: (Background)

In Docker, to copy and save files, we can leverage a few commands. (1) first docker cp, Once files are copied. Then (2) one must do some sort of "commit" to keep the updated image (i.e., at least in Docker that is how it works.)

  1. Docker cp - Copy files/folders between a container and the local filesystem
  2. Docker commit - Create a new image from a container’s changes

Singularity: 1. Writable Mode: You can enter the sandbox with sudo singularity shell --writable sandbox/. Then, you can make your changes there. 2. Save: In writeable mode, changes are saved in image/directory. Then, you can create a read-only image from the changes made in the sandbox. 3. Privilege Mode One must use privilege mode (sudo) to make all the changes.

-- itsmrbeltre
Source: StackOverflow