I'm trying to run docker command on Windows 10 Enterprise as Admin:
docker-compose exec --user magento2 web find /var/www/sample-data -type d -exec chmod g+ws {} \;
but I got the error:
find: missing argument to `-exec'
I was trying to escape by using '' or "":
docker-compose exec --user magento2 web "find /var/www/sample-data -type d -exec chmod g+ws {} \;"
but it throws anouther error
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:262: starting container process caused "exec: \"find /var/www/sample-data -type d -exec chmod g+ws {} \\\\;\": sta
t find /var/www/sample-data -type d -exec chmod g+ws {} \\;: no such file or directory"
How I can resolve this issue? Normaly when I insert this command inside the container - everything works fine.
Use sh instead:
docker-compose exec --user magento2 web sh -c 'find /var/www/sample-data -type d -exec chmod g+ws {} \;'
Related
How would one replace text in all files within a given directory (recursively) while in the xonsh shell?
For example, how would I rewrite the below bash command:
find . -type f -name "*baz*" -exec sed -i 's/foo/bar/g' {} +
I might try this:
for fpath in pg`*baz*`:
if not fpath.is_file():
continue
fpath.write_text(fpath.read_text().replace('foo', 'bar'))
Just add the quotes to tell xonsh that {} and + are the arguments:
find . -type f -name "*baz*" -exec sed -i 's/foo/bar/g' '{}' '+'
The complete example of testing your command in xonsh:
echo 'foo foo' > some_baz_file
find . -type f -name "*baz*" -exec sed -i 's/foo/bar/g' '{}' '+'
cat some_baz_file
# bar bar
Another way is to use the xonsh macro command and just run bash line as is:
bash -c! find . -type f -name "*baz*" -exec sed -i 's/foo/bar/g' {} +
To simplify this approach there is xontrib-sh extension that allows just add the ! sign before the command:
! find . -type f -name "*baz*" -exec sed -i 's/foo/bar/g' {} +
I run docker-compose up -d and then ssh into the container. I can load the site via localhost just fine but when I try to edit the source code on my local it does not let me due to permission errors. This is the ls -la output on container vs local:
Container:
Local:
My dockerfile has the chown command:
My local user is called pwm. I tried running chown -R pwm:pwm ../app from host at which point I am able to edit files but then I get laravel permission denied errors. Then I need to runchown -R www-data:www-data ../app again to fix it.
How can I fix this?
For a development environment, my go-to solution for this is to setup an entrypoint script inside the container that starts as root, changes the user inside the container to match that of the file/directory owner from a volume mount (which will be your user on the host), and then switch to that user to run the app. I've got an example of doing this along with the scripts needed to implement this in your own container in my base image repo: https://github.com/sudo-bmitch/docker-base
In there, the fix-perms script does the heavy lifting, including code like the following:
# update the uid
if [ -n "$opt_u" ]; then
OLD_UID=$(getent passwd "${opt_u}" | cut -f3 -d:)
NEW_UID=$(stat -c "%u" "$1")
if [ "$OLD_UID" != "$NEW_UID" ]; then
echo "Changing UID of $opt_u from $OLD_UID to $NEW_UID"
usermod -u "$NEW_UID" -o "$opt_u"
if [ -n "$opt_r" ]; then
find / -xdev -user "$OLD_UID" -exec chown -h "$opt_u" {} \;
fi
fi
fi
That script is run as root inside the container on startup. The last step of the entrypoints that I run will call something like:
exec gosu ${app_user} "$#"
which runs the container command as the application user as the new pid 1 executable.
In a build process I need to call zipalign which is on a certain path in the docker container that I'm using:
$ docker run nathansamson/flutter-builder-docker:v0.7.3 find . -iname zipalign
./opt/android-sdk-linux/build-tools/28.0.1/zipalign
This path can change, if the docker container is updated and there is a new android sdk. For example this could be the path in the future:
$ docker run nathansamson/flutter-builder-docker:v0.9.9 find . -iname zipalign
./opt/android-sdk-linux/build-tools/42.0.0/zipalign
So instead of hardcoding the call to
docker run nathansamson/flutter-builder-docker:v0.7.3 \
/opt/android-sdk-linux/build-tools/28.0.1/zipalign -h
I would like a generic solution that finds the path to zipalign automatically. I have tried it with a subshell
$ docker run nathansamson/flutter-builder-docker:v0.7.3 $(find . -iname zipalign) -h
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:348: starting container process caused "exec: \"-h\":
executable file not found in $PATH": unknown.
ERRO[0001] error waiting for container: context canceled
and with a wildcard for the folder:
$ docker run nathansamson/flutter-builder-docker:v0.7.3 /opt/android-sdk-linux/build-tools/*/zipalign -h
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:348: starting container process caused "exec:
\"/opt/android-sdk-linux/build-tools/*/zipalign\": stat /opt/android-
sdk-linux/build-tools/*/zipalign: no such file or directory": unknown.
ERRO[0001] error waiting for container: context canceled
So subshells and wildcard don't work in Docker. Any ideas how I can find the path to zipalign whenever I'm calling it?
In your Dockerfile you control the entire environment. It's often easiest to cause things to appear in their "natural" places, like /usr/bin. You also have the advantage that, within a single Docker image, there will only be one version of the tools installed.
I might do something like this:
RUN for f in $PWD/opt/android-sdk-linux/build-tools/*/*; do \
ln -s $f /usr/local/bin; \
done
CMD ["zipalign", "-h"]
Another approach that might work is to use a build argument or an environment variable to hold the version number. If you do that then you can set up a known path name.
ARG version
RUN curl -LO http://.../android-sdk-linux-${version}.tar.gz \
&& tar xzf android-sdk-linux-${version}.tar.gz \
&& rm -f android-sdk-linux-${version}.tar.gz \
&& cd opt/android-sdk-linux-build-tools \
&& ln -s ${version} current
CMD ["./opt/android-sdk-linux/build-tools/current/zipalign"]
find can execute something by using the -exec option.
find . -name zipalign -exec bash -c '"$0"' {} \;
In your example:
docker run nathansamson/flutter-builder-docker:v0.7.3 find . -name zipalign -exec bash -c '"$0"' {} \;
If there is nothing that can give you any hints, and you need to just find it, then find will probably do it. Something like:
find /opt -name zipalign -type f
If you can give it more specific starting point, instead of just /opt, then it will run faster.
If you want to execute it (and pass in "-h") in one line, you could do:
$(find /opt -name zipalign -type f) -h
cat to standard output inside a Dockerfile is giving the following errors when building the image:
cat: read error: I/O error
cat: can't open '/proc/sys/net/ipv4/route/flush': Permission denied
cat: read error: I/O error
cat: can't open '/proc/kmsg': Operation not permitted
cat: read error: Invalid argument
The cat command is being run as the last line in the Dockerfile, like this:
RUN find / -print -exec test -f {} \; -exec cat {} \; | wc -c
Note that I do not get these errors, and in fact, it works, when I do this instead,
RUN find . -print -exec test -f {} \; -exec cat {} \; | wc -c
How can this be solved to enable cat for any file in the image during the build?
Thanks
I made the new user called "rails"
Then owner and group of all the directories and files are set to "rails"
I do have the appliation in /var/www/html/app
So I should do $ cd /var/www/html/app and execute this?
find . -type d | xargs chmod 0755 and find . -type f | xargs chmod 0644
Is it going to set up permission for everything, and it'll be all fine?
Assuming /var/www/html/app is the app folder for a rails application located at /var/www/html, you should be running
cd /var/www/html
find . -type d | xargs chmod 0755
find . -type f | xargs chmod 0644
You might be literally interpreting 'and' incorrectly.