Cant connect to smb share with ubuntu container, but only if I use the COPY build command

Simple dockerfile to build a ubuntu image that will connect to my SMB share.

FROM ubuntu:latest
RUN apt install nano -y
RUN apt install cifs-utils -y
RUN mkdir media/share
COPY ./files/ /etc/

Inside the ./files folder is a txt file with my credentials for smb. After I build and run the container, I run the command “mount -t cifs -o vers=3.0,credentials=/etc/.smb_credentials.txt //ip-addr/dataset_name /media/share” and I get an error “mount error(13): Permission denied Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)”.

But if I quote out the “COPY” command and then manually add the credential text file it connects without a problem. I have went thru and checked permissions to all the files involved and they all seem to be fine. I have even checked the file permissions when it works and made sure to set them to the same when it doesnt work. It still wont work. I dont get what is so detrimental about the copy command that makes this throw an error no matter what I do.

According the mount man page, the capability CAP_SYS_ADMIN is required.
You can run the container with docker run --privileged or docker run --cap-add CAP_SYS_ADMIN

The prefered way would be to use a named volume baked by cifs, as it would mount the remote filesystem before the container is started, thus doesn’t require to add capabiliites to the container. But it does not allow to use a credentials file.

Ya I use that capability in both cases, its not that. Its something to do with copying the credential file over I just don’t understand what

It’s content looks like this (no leading space between = and the value)?


The man pages do not mention if the file must have a specify permission mask set.
Though, what commes to mind is that the file might have dos/windows line endings instead of unix file endling…