Gabriel Pulga
Gabriel Pulga

Reputation: 293

How do I find where a file is located inside container?

I'm trying to give special permissions to a file located inside a container but I'm getting a "No such file or directory" error message.

The Dockerfile basically runs a R Script that generates an output.pptx file located inside an output folder created inside the container.

I want to send that output into a s3 bucket but for some reason it isn't finding the file inside the container.

# Make the output directory
RUN mkdir output 

# Process main file
CMD ["RScript", "Script.R"]

# install AWS CLI
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
RUN unzip awscliv2.zip
RUN ./aws/install -i /usr/local/bin/aws -b /usr/local/bin

# run AWS CLI to push output file to s3 folder
RUN chmod 775 ./output/*.pptx
RUN aws s3 cp ./output/*.pptx s3://bucket

Could this be related to the path I'm using for the file?

Upvotes: 0

Views: 604

Answers (1)

r2evans
r2evans

Reputation: 160687

(Edited to fix a word-swap brain-fart in the first version.)

I get the idea that there is a misunderstanding of how the image should be used. That is, a DOCKERFILE creates an image, and the CMD is not actually run when building the image.

Up front:

  • an image is really just a tarball with filesystems; multiple "layers" are there, to indicate the layers of the build process (which can be squashed); an image has no "running" component, no processes are active in an image; and
  • a container is an image that is in a running state. It might be the CMD you specify, or it might be something else (e.g., docker run -it --rm myimage /bin/bash to run a bash shell with the container as the filesystem/environment). When the running command finishes and exits, the container is stopped.

Typically, you create an image "once" (security updates and such notwithstanding), and then run it as needed (either manually or via some trigger, e.g., cron or CI triggers). That might look like

docker run --rm myimage                 # using the default `CMD`
docker run --rm myimage R Script.R      # specifying the command manually

with a couple assumptions:

  • the image has R installed and within the PATH ... though you could specify the full /path/to/bin/R instead; and
  • the default working directory (dockerfile's WORKDIR directive) contains Script.R ... or you can specify the full internal path to Script.R

With this workflow, I suggest a few changes:

  • from the DOCKERFILE, remove the lines after # run AWS CLI;

  • add to Script.R steps to copy the file to your S3 instance, either using the awscli you installed in the image, or by using the aws.s3 R package (which might preclude the need to install the awscli);

  • I don't use AWS S3, but I suspect that you need credentials to be able to access the bucket; there are many ways for dealing with images and "secrets" like S3 credentials, the most naïve approaches involve hard-coding the credentials into the container, which is a security risk; others involve "docker secrets" or environment variables. For instance,

    docker run -it --rm -e "S3TOKEN=asldkfjlaskdf"
    

    though even that might be intercepted by neighboring users on the docker host.

Upvotes: 1

Related Questions