I'm trying to run a command in script using nix-shell -p [package] --command [comand] and getting an error Permission denied on files, that the command needs to operate on. The command needs only read access and if I try to do nix-shell -p [package] and then run the [command] there by hand, then everything is okay, but if I try to do it through the --command [command] it gives me an error. Why is that?
Edit:
The command looks like this: nix-shell -p ormolu --command "ormolu --mode check $(find . -name '*.hs')"
This has nothing to do with nix-shell (or ormolu). Try this instead:
nix-shell -p ormolu --command "find . -name '*.hs' -exec ormolu --mode check {} + "
The reason you've got permission denied is that you actually passing the first output of the find command to ormolu, and trying to execute the rest of the .hs files.
Related
I try to execute the following line:
docker exec --user www-data nextcloud_docker php /var/www/html/occ db:convert-filecache-bigint
which returns a prompt:
This can take up to hours, depending on the number of files in your instance!
Continue with the conversion (y/n)? [n]
Unfortunately the docker exec command ends (returns to shell) and I am not able to start the occ command.
How can I solve this?
Thanks.
You can try setting the -i flag on the docker command and piping a 'y' into it, like this
echo y | docker exec -i --user www-data nextcloud_docker php /var/www/html/occ db:convert-filecache-bigint
or you can run the command fully interactively with the -it flags like this
docker exec -it --user www-data nextcloud_docker php /var/www/html/occ db:convert-filecache-bigint
occ has a -n switch.
I run it from cron, including the update. I have these lines in /home/update-nextcloud-inside-container.sh inside my container:
#!/bin/bash
date
sed -i 's~www-data:/var/www:/usr/sbin/nologin~www-data:/var/www:/bin/bash~g' /etc/passwd
su -c "cd /var/www/nextcloud; php /var/www/nextcloud/updater/updater.phar --no-interaction" www-data
su -c "cd /var/www/nextcloud; ./occ db:add-missing-indices -n" www-data
su -c "cd /var/www/nextcloud; ./occ db:convert-filecache-bigint -n" www-data
sed -i s~www-data:/var/www:/bin/bash~www-data:/var/www:/usr/sbin/nologin~g /etc/passwd
and the host cron launches a script with these lines:
ActiveContainer=$(/home/myusername/bin/lsdocker.sh | grep next )
docker exec -i ${ActiveContainer} /home/update-nextcloud-inside-container.sh
I see now I am missing taking the instance off-line for running convert-filecache. I'll have to add that.
Edit: (lsdocker.sh is a script that uses docker ps to list just the active container names)
I have generated a openapi json file, and I wish to create a typescript client using docker.
I have tried to do something similar to what is on the openapi generator site (https://openapi-generator.tech/ - scroll down to docker part), but it doesn't work.
Command from site:
docker run --rm \
-v $PWD:/local openapitools/openapi-generator-cli generate \
-i /local/petstore.yaml \
-g go \
-o /local/out/go
What I have tried:
docker run --rm -v \
$PWD:/local openapitools/openapi-generator-cli generate -i ./openapi.json \
-g typescript-axios
No matter what I do, there is always a problem with the ./openapi.json file. The error which occours:
[error] The spec file is not found: ./openapi.json
[error] Check the path of the OpenAPI spec and try again.
I have tried the things below:
-i ~/compass_backend/openapi.json
-i openapi.json
-i ./openapi.json
-i $PWD:/openapi.json
cat openapi.json | docker run .... (error, -i is required)
I am out of ideas. The error is always the same. What am I doing wrong?
I was able to solve the problem by switching from bash to powershell. Docker uses windows path notation and I was trying to use bash notation. If you type pwd in bash you get this:
/c/Users/aniemirka/compass_backend
And if you type pwd in powershell you get this:
C:\Users\aniemirka\compass_backend
So docker was trying to mount a volume to /c/Users/aniemirka/compass_backend\local, and it couldn't read it because it is not windows notation, so the volume didn't exist.
I am new to docker and am experimenting with trying to get firefox GUI up and running. The Dockerfile I have is:
FROM ubuntu:21.10
RUN apt-get update
RUN apt-get install -y firefox
RUN groupadd -g GID <USERNAME>
RUN useradd -d /home/<USERNAME> -s /bin/bash \
-m <USERNAME> -u UID -g GID
USER <USERNAME>
ENV HOME /home/<USERNAME>
CMD /usr/bin/firefox
...where UID is userID and GID is groupID
I then build with:
$> docker build -t gui .
The image build completes successfully. Then I do:
$> docker run -v /tmp/.X11-unix:/tmp/.X11-unix \
-h $HOSTNAME -v $HOME/.Xauthority:/home/$USER/.Xauthority \
-e DISPLAY=$DISPLAY gui
At this point I get the error:
"docker: invalid reference format: repository name must be lowercase."
It's almost as if docker is trying to interpret the X server directory binding and display variable setting as a repository name.
What I am doing wrong?
Thanks in advance...
In fact the error you get tells you that docker cannot understand the reference i.e. the name of the image you are trying to run. As well explained by David Maze. He has proposed to debug it thanks to an echo command.
If you follow his advice, for example in your command if $HOSTNAME is not defined you will see the command with variable expanded and be able to see that it will lead to the observed error if launched. To fix it you can quote your variable (always a good advice to prevent errors) and check that each variable is defined. In your case a missing $HOSTNAME is my best guess.
docker run -v /tmp/.X11-unix:/tmp/.X11-unix -h -v /Users/xxx/.Xauthority:/home/xxx/.Xauthority -e DISPLAY=/mydisplay gui
# docker: invalid reference format: repository name must be lowercase.
David Maze's comment gave the solution:
You're not quoting your environment variable expansions, so if $HOSTNAME is empty or $HOME contains a space you can get errors like this. Try putting the word echo in front of the command and seeing how the shell expands it.
When my Dockerfile does the RUN command:
RUN npm-cli-adduser -r https://$PRIVATE_REPOSITORY_URL/repository/npm-read -u $PRIVATE_USERNAME -p "$PRIVATE_PASSWORD" -e service-foobar#example.com
It echos the private environment variables in the terminal. I would like to hide these variables, so that users who read the terminal do not see it.
Is this possible?
You can use docker secrets, but you will need to store the variable in a file as far as i understand
Like this:
Dockerfile
FROM node:12
RUN --mount=type=secret,id=mysecret,dst=/foobar echo $(cat /foobar) >> test.txt
# In your case
# RUN npm-cli-adduser -r https://$PRIVATE_REPOSITORY_URL/repository/npm-read -u $PRIVATE_USERNAME -p $(cat /foobar) -e service-foobar#example.com
Build command
docker build --secret id=mysecret,src=mysecret.txt . -t docker-debug
mysecret.txt contect:
YOURPASSWORD
Reference
I have a shell script containing a call to docker run. The script looks like this:
#!/bin/sh
#Local directory where your data is.
PATH_TO_EXPORTS="/home/user/data"
iType_NAME="iType.csv"
colIDs="X,Y,W,Z"
FLAG="FALSE"
#These next three variables don't need to, and should not be changed.
#They refer to locations within the docker container - DO NOT CHANGE !!!
IMG_EXPORTS_DIR="/home/rstudio/project/exports"
#Execute docker run to carry out your analysis
docker run -v $PATH_TO_EXPORTS:$IMG_EXPORTS_DIR \
-e PATH_TO_EXPORTS=$IMG_EXPORTS_DIR \
-e iType_NAME=$iType_NAME \
-e colIDs=$colIDs \
-e FLAG=$FLAG \
--user "$(id -u)" \
my_docker_image:3.0
If I try to run this script via command line by calling: sh myScript.sh , I get the following error:
docker: invalid reference format.
See 'docker run --help'.
However, if I manually run the docker run ... command on the command line, everything works as expected.
Does anybody know why this docker run ... command fails when inside a shell script ?
Many thanks in advance !
-M.