Forrest logo
back to the docker tool

docker:tldr:b94d0

docker: Copy a file or directory from the host to a container, following symlinks (copies the symlinked files directly, not the symlinks themselves).
$ docker cp --follow-link ${path-to-symlink_on_host} ${container_name}:${filename_or_directory_in_container}
try on your machine

The docker cp --follow-link command is used to copy files between the host machine and a running Docker container while also following symbolic links.

Here is a breakdown of the command arguments:

${path-to-symlink_on_host}: This is the path to the symbolic link on the host machine that you want to copy. It could be a file or a directory.

${container_name}: This is the name or ID of the target Docker container where you want to copy the file or directory.

${filename_or_directory_in_container}: This is the destination path inside the Docker container where you want to copy the file or directory.

By using the --follow-link option, the command will also follow symbolic links when copying the files. This means that if the symbolic link points to a file or directory, the actual target of the link will be copied instead of the link itself.

For example, if you have a symbolic link /host/symlink on the host machine that points to /host/file.txt, and you want to copy it into a container named mycontainer, you can use the command:

docker cp --follow-link /host/symlink mycontainer:/container/file.txt

This will copy the target file /host/file.txt into the directory /container inside the running container mycontainer. The --follow-link option ensures that the actual file contents of the target are copied, not the symbolic link itself.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the docker tool