can't delete folder in Docker container - docker

within a running docker container I am trying to erase a folder. However, the OS seems to find that some files are not able to delete it. During the deletion process it says something like can not find file for several files supposed to be within the folder I am trying to delete. Is there a way to repair this?
I tried:
fsck -f /MyFolder
fsck from util-linux 2.27.1
e2fsck 1.42.13 (17-May-2015)
fsck.ext2: Is a directory while trying to open /MyFolder
The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem. If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193
or
e2fsck -b 32768
OTHER error messages:
rm: cannot remove 'MyFolder/webpack.config.js': No such file or directory
rm: cannot remove 'MyFolder/webpack.config.js.bck2': No such file or directory
rm: cannot remove 'MyFolder/webpack.config.js.bck3': No such file or directory
I also noticed a lot of files with size 0 with the names of the files declared as 'cannot remove...'

Related

Exclude a directory from `podman/docker export` stream and save to a file

I have a container that I want to export as a .tar file. I have used a podman run with a tar --exclude=/dir1 --exclude=/dir2 … that outputs to a file located on a bind-mounted host dir. But recently this has been giving me some tar: .: file changed as we read it errors, which podman/docker export would avoid. Besides the export I suppose is more efficient. So I'm trying to migrate to using the export, but the major obstacle is I can't seem to find a way to exclude paths from the tar stream.
If possible, I'd like to avoid modifying a tar archive already saved on disk, and instead modify the stream before it gets saved to a file.
I've been banging my head for multiple hours, trying useless advices from ChatGPT, looking at cpio, and attempting to pipe the podman export to tar --exclude … command. With the last I did have small success at some point, but couldn't make tar save the result to a particularly named file.
Any suggestions?
(note: I do not make distinction between docker and podman here as their export command is completely the same, and it's useful for searchability)

"Device or resource busy" when i try move /etc/resolv.conf in ubuntu:18.04. How fix it?

I have a VPN client in my Docker container (ubuntu:18.04).
The client must do the following:
mv /etc/resolv.conf /etc/resolv.conf.orig
Then the client should create new /etc/resolv.conf with their DNS servers. However, the move fails with an error:
mv: cannot move '/etc/resolv.conf' to '/etc/resolv.conf.orig': Device or resource busy
Can this be fixed? Thank you advance.
P.S.: I can 't change the VPN client code.
Within the Docker container the /etc/resolv.conf file is not an ordinary regular file. Docker manages it in a special manner: the container engine writes container-specific configuration into the file outside of the container and bind-mounts it to /etc/resolv.conf inside the container.
When your VPN client runs mv /etc/resolv.conf /etc/resolv.conf.orig, things boil down to the rename(2) syscall (or similar call from this family), and, according to the manpage for this syscall, EBUSY (Device or resource busy) error could be returned by few reasons, including the situation when the original file is a mountpoint:
EBUSY
The rename fails because oldpath or newpath is a directory that is in use by some process (perhaps as current working directory, or as root directory, or
because it was open for reading) or is in use by the system (for example as mount point), while the system considers this an error. (Note that there is no
requirement to return EBUSY in such cases — there is nothing wrong with doing the rename anyway — but it is allowed to return EBUSY if the system cannot otherwise handle such situations.)
Though there is a remark that the error is not guaranteed to be produced in such circumstances, it seems that it always fires for bind-mount targets (I guess that probably this happens here):
$ touch sourcefile destfile
$ sudo mount --bind sourcefile destfile
$ mv destfile anotherfile
mv: cannot move 'destfile' to 'anotherfile': Device or resource busy
So, similarly, you cannot move /etc/resolv.conf inside the container, for it is a bind-mount, and there is no straight solution.
Given that the bind-mount of /etc/resolv.conf is a read-write mount, not a read-only one, it is still possible to overwrite this file:
$ mount | grep resolv.conf
/dev/sda1 on /etc/resolv.conf type ext4 (rw,relatime)
So, the possible fix could be to try copying this file to the .orig backup and then rewriting the original one instead of renaming the original file and then re-creating it.
Unfortunately, this does not meet your restrictions (I can 't change the VPN client code.), so I bet that you are out of luck here.
Any method that requires moving a file onto /etc/resolv.conf fails in docker container.
The workaround is to rewrite the original file instead of moving or renaming a modified version onto it.
For example, use the following at a bash prompt:
(rc=$(sed 's/^\(nameserver 192\.168\.\)/# \1/' /etc/resolv.conf)
echo "$rc" > /etc/resolv.conf)
This works by rewriting /etc/resolv.conf as follows:
read and modify the current contents of /etc/resov.conf through the stream editor, sed
the sed script in this example is for commenting out lines starting with nameserver 192.168.
save the updated contents in a variable, rc
overwrite the original file /etc/resolv.conf with updated contents in "$rc"
The command list is in parentheses to operate in a sub-shell to avoid polluting the current shell's name space with a variable name rc, just in case it happens to be in use.
Note that this command does not require sudo since it is taking advantage of the super user privileges available by default inside the container.
Note that sed -i (editing in-place) involves moving the updated file onto the original and will not work.
But if the visual editor, vi, is available in the container, editing and saving /etc/resolv.conf with vi works, since vi modifies the original file directly.

Unable to copy the file to docker host

I am trying to execute the below docker command where I am trying to get the 'Orthanc.json" file to my system folder which is "orthanc".
docker run --rm --entrypoint=cat jodogne/orthanc /etc/orthanc/orthanc.json >
orthanc/orthanc.json
under /etc/orthanc/orthanc.json - It is a directory and not a file - Am not able to use vim editor to read/open the file. - This is a public one. Anyone can access using this link Orthanc link
I get the below error message, Can you please help me understand what is the issue?
-bash: /orthanc/orthanc.json: Is a directory
orthanc.json should be a file but why does it treat it as a directory?
when I use vim orthanc.json, it throws an error message that it's a directory.
What should I be doing to see this as a config file as I have to make changes to it?
You've somehow already got a directory named /orthanc/orthanc.json on your host system. Remove it and try again.
rmdir /orthanc/orthanc.json # if empty
rm -rf /orthanc/orthanc.json # if not empty -- but see what's in there first!

rsync --include is not working as expected

I am trying to backup jenkins home directory (/home/ubuntu/.jenkins/) using rsync to the target directory /opt/jenbkup/. Since the directory traversal seems not working as expected, I have gone with single directory in the filter:
rsync -avr --include="jobs/*/config.xml" --exclude="*" /home/saga/.jenkins /opt/jenbkup
But nothing is copied. I also tried with exact file path in the include and did not work.
rsync -avr --include="jobs/job1/config.xml" --exclude="*" /home/saga/.jenkins /opt/jenbkup
File is not copied to destination. I don't understand whats wrong here. Some one please assist.
I assume, that you would only backup the config.xml files in your JENKINS_HOME, then this should work:
rsync -av --include="*/" --include="config.xml" --exclude="*" \
--delete --prune-empty-dirs /home/saga/.jenkins/ /opt/jenbkup/
Short explaination of the used options:
--include="*/" traverse all directories
--include="config.xml" include only files named "config.xml"
--exclude="*" exlude everything
--delete delete non-existing files in the backup
--prune-empty-dirs delete empty directories from the backup

docker cp not working

I'm following this tutorial and when I get to the part where I call:
cp /tf_files/stripped_retrained_graph.pb bazel-bin/tensorflow/examples/android/assets/stripped_output_graph.pb
and
cp /tf_files/retrained_labels.txt bin/tensorflow/examples/android/assets/imagenet_comp_graph_label_strings.txt
They both say "No such file or directory".
As you can see in this image I can cd to the tf_files folder and see that the files are there.
I can also cd to /tensorflow/tensorflow/examples/android/assets and call ls which shows there's just a BUILD file there.
In the cp command is there supposed to already be a stripped_output_graph.pb file in the destination which gets replaced? Or is it meant to just be creating a new file there?
Is there some way of doing cp [source] [current directory] rather than specifying the destination as a path?
I've tried removing the file path part in hope that it just uses the source filename but that doesn't work.
Calling
cp /tf_files/stripped_retrained_graph.pb /tensorflow/tensorflow/examples/android/assets/stripped_output_graph.pb
and
cp /tf_files/retrained_labels.txt /tensorflow/tensorflow/examples/android/assets/imagenet_comp_graph_label_strings.txt
finally worked, wasn’t at all obvious that I’d have to change the destination path or what it should be though.
Also I accidentally saved a file as .p rather than .pb but managed to remove it using $ docker exec <container> rm -rf /tensorflow/tensorflow/examples/android/asset
s/stripped_output_graph.p
Now I managed to copy the files in correctly, but then when I installed the app it was still just running the regular demo app.
Not sure why it didn’t work, so frustrating.
When I rebuilt it after copying the files in I got these conflict messages
Are these normal to have?
It looks like maybe a different labels file is taking priority over mine, how can I reach the external/inception5h/imagenet_comp_graph_label_strings.txt file to delete it so my file is used instead?
Does the “external” part mean that I can’t actually access it?

Resources