podman: .dockerignore file not excluding socket files - docker

When I try to build an image I get the error,
ERRO[0007] Can't add file /home/ccade/.local/share/containers/storage/overlay/dfa9bea029efc1222500f997bf64d37a0eb4800bff3a87e916d3b8aaa213bd3e/diff/var/cache/dnf/grafana-13e251e56a0c8862/pubring/S.gpg-agent to tar: archive/tar: sockets not supported
I added a .dockerignore file to the build directory. I tried the following entries:
S.gpg-agent
*S.gpg-agent
**/S.gpg-agent
*/S.gpg-agent
however, the build each time tries to add that file and produces the error. I thought specifying that file name in .dockerignore would mean it got excluded from the build.

Try to use buildah, maybe your version of podman has a known bug related to .dockerignore.

Related

Docker containers complain about missing files which exist in their filesystem

I recently moved my code repo from a One drive folder to my C: drive, trying to escape sync issues wiping files (thats another issue). Before doing so both my dev and prod compose files worked as expected (under source control).
Moving the files across (cloning from the repo and checking out to the branch) I ran my dev compose file which worked again as expected however my prod started complaining about "no such file or directory", "not found". I decided to snapshot the filesystem and check and could see the files and could cat the contents. So why is docker complaining?
My compose file does not use any hardcoded file paths, all relative and its evident the files are being copied across.
Compose errors:
exec docker/deployment/folder/scripts/run.sh: no such file or directory
Snapshot:
/app$ cat docker/deployment/folder/scripts/run.sh
#!/bin/sh
As previously mentioned this worked running from a diffirent local dir location. I can't imaging how that would make any diffirence.
Thanks in advance for any support.
Found the issue, vs code had updated the end-of-line sequence to crlf instead of lf.

Copy directory into docker build no matter if empty or not - fails on "COPY failed: no source files were specified"

I have directory csv in context directory of docker build. I want to copy it into docker image in all circumstances (for empty directory in host an empty directory inside image is created, for nonempty directory in host it is copied with all content).
The COPY csv/* /csv/ gives COPY failed: no source files were specified error when the directory is empty.
Similar questions I found on SO are differing from my case in either setup or intention (multistage build, copying existing jar, certainly existing file) so I choose Q&A-style here rather than messing question with unrelated answer. This Github issue is also related.
The solution is to use
COPY csv/. /csv/
This question gave me a hint (although the behavior desired by me is unwanted for its OP).

Docker configuration does not find existing file?

I try to configure and run a docker file in IntelliJ Rider.
During the build, I get the following error:
Step 7/17 : COPY ["src/No.Services/No.Gf/No.Gf.Api/No.Gf.Api.csproj",
"src/No.Services/No.Gf/No.Gf.Api/"]
Error response from daemon: COPY failed: file not found in build context or excluded by .dockerignore:
stat src\No.Services\No.Gf\No.Gf.Api\No.Gf.Api.csproj: file does not exist
The file is right where the path points to. It's not exluded in .dockerignore.
I am out of options here?
Step 6 is:
Step 6/17 : WORKDIR /src
Maybe this is adding one "/src" to much and in step 7 it's finally looking for the file in /src/src/...?
I don't know your physical directory hierarchies, but I would say that the reason of the error may be the original relative path between the Dockerfile and the csproj. With the csproj location stated like src/No.Services/No.Gf/..., the Dockerfile will have to be at the same level of that src folder, for the copy to be successful.
Could you please verify this?
(If you are working with a typical dotnet solution on top of the project, setting the Dockerfile in the root of the solution may solve your error, since it will respect the folders' hierarchy.)
Regarding the other topics:
The WORKDIR command refers to the working directory in the container (reference), so, I would say that it is not the reason for your error, because it seems that, when copying, the file is not found in its source.
When the copy into the container is successful, it will probably be in a directory like src/src/No.Services/No.Gf/..., but this is after copying, inside the container.

Docker Copy failed no source files were specified

I am trying to copy a jar file in my dockerfile. whne I run build, I can see the jar under target/dockerbuild. But docker does not see the file and I am getting following error.
COPY failed: no source files were specified
My docker file has those lines for copy operation:
ENV MY_HOME=/usr/local/myhome
COPY target/dockerbuild/my.jar $MY_HOME
Why it cannot find the jar although it exists under the target.
Verify that in your .dockerignore do not have that path (target) in your exceptions
Your error looks like it could be one of the following:
The file doesn't exist in the specified path
The path doesn't exist (relative to the build context - if you use 'docker build .' then the specified path must exist relative to the current directory)
Please can you share what you run to build your docker image (so we can see the build context) and also your directory structure
That error said file target/dockerbuild/my.jar is not exist. The architecture of COPY in Dockerfile is:
COPY {file in your host} {path of target in docker image}
I had a very similar situation.
ls target/dockerbuild/my.jar
proofed that the file exists but docker build claimed that no source files were specified. However there also was a tiny hint that I did not notice for some time:
When using COPY with more than one source file, the destination must be a directory and end with a /
Though I only had one file I added the / to the copy destination and the build succeeded.

Why is my dockerfile not copying directories

in my dockerfile I have these two lines:
ADD /ansible/inventory /etc/ansible/hosts
ADD /ansible/. /ansiblerepo
The first line works, as I can run the container and see my hosts file has been populated with all the ips from my inventory file.
The second line doesn't appear to be working though. I'm just trying to copy all the files/subdirectories of ansible and copy them over to the ansiblerepo directory inside the new container.
There are no errors while building the image, but again ansiblerepo is just an empty directory and nothing has copied over to it. I assume I'm just missing a back slash or something.
Docker ADD and COPY commands work relative to the build directly, and only for files in that directory that weren't excluded with a .dockerignore file. The reason for this is that builds actually run on the docker host, which may be a remote machine. The first step of a docker build . is to package up all the files in the directory (in this case .) and send them to the host to run your build. Any absolute paths you provide are interpreted as relative to the build directory and anything you reference that wasn't sent to the server will be interpreted as a missing file.
The solution is to copy /ansible to your build directory (typically the same folder as your Dockerfile).
Make sure that in your ".dockerignore" file, it does not excluded everything. usually, dockerignore file has these lines
*
!obj\Docker\publish\*
!obj\Docker\empty\
this means that everything is ignored except publish and empty folders.
Removing trailing /. from source directory should fix the ADD command.
On a related note, Docker Best Practices suggest using COPY over ADD if you don't need the URL download feature.

Resources