I have a Docker container and need to pass a single string (an array of strings would work too, but as far as I know this is not possible) containing the names of the file present in the current directory.
My first strategy to get the filenames inside the container was running the command docker build -t doc-validate . && docker run doc-validate (printf "%s " $(ls -p | grep -v /))
, to send the output of (printf "%s " $(ls -p | grep -v /))
directly into the container's STDIN, however, I get zsh: bad pattern: (printf %s Dockerfile
returned as an error; seems to me that the container or the shell is trying to get 'Dockerfile' executed somewhere and I don't know why this happens, as running this same printf
command directly in the terminal works as expected (printing only file names in the current directory).
My second approach was trying to send these filenames as an environment variable to the container. Running PROJECT_FILES=(printf "%s " $(ls -p | grep -v /))
in the terminal works as expected, $PROJECT_FILES
outputs these filenames. However, if I try to pass it directly into the container like this: docker build -t doc-validate . && docker run --env PROJECT_FILES=(printf "%s " $(ls -p | grep -v /)) doc-validate
I get the same zsh: bad pattern: PROJECT_FILES=(printf %s Dockerfile
as an error.
Seems to me that it the commands are failing before even entering the container due to 'zsh:' being in the error output, however, I don't see why running them standalone in the terminal works and why passing them as parameters to the container is being such a headache.
How can I get the output of running (printf "%s " $(ls -p | grep -v /))
in my local machine as a value accessible inside the container?
Dockerfile:
FROM node:16
WORKDIR /moduleRoot
COPY package.json /moduleRoot
RUN npm install
COPY . /moduleRoot/
# Authorize execution of entrypoint bash script
RUN chmod +x /moduleRoot/docker-container-entrypoint.sh
# these values below will be set later, just register them explicitly here
ENV PROJECT_FILES=""
CMD [ "/moduleRoot/docker-container-entrypoint.sh" ]
Bash entrypoint (docker-container-entrypoint.sh file in CMD):
#!/bin/bash
echo "Args are: $@"
echo "PROJECT_FILES=$PROJECT_FILES"