I am trying to save a .txt file from an R session running through docker. To run this docker image run the following code:
docker run -e PASSWORD=xxx --rm -p xxx:xxx -v ~/ad_R:/home/rstudio/ad_R -v ~/ad_data:/home/rstudio/ad_data rocker/tidyverse
I do not show here the password or the port in which they are executed.
However my question is, when I execute the following code:
write.table(all_blast_vir_updated,file="/home/rstudio/ad_R/all_blast_vir_updated.txt",sep="\t")
It gives me this error:
Error in file(file, ifelse(append, "a", "w")) :
cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
cannot open file '/home/rstudio/ad_R/all_blast_vir_updated.txt': Permission denied
when I run the following code in the R terminal:
system('ls -ld ad_R;ls -ld ad_data')
I get the following result:
drwxr-xr-x 3 root root 4096 Jul 9 10:06 ad_R
drwxr-xr-x 1 root root 516 Jul 6 15:06 ad_data
docker inspect rocker/tidyverse
[
{
"Id": "sha256:93f0dfaee7413331b085e3353ecfd99de4c95a3c38344f367a1e20938f350a94",
"RepoTags": [
"rocker/tidyverse:latest"
],
"RepoDigests": [
"rocker/tidyverse@sha256:0fcc86754ed90b3e5a3dcaed27ad967de2859705f85c28d9284e16aa9856548b"
],
"Parent": "",
"Comment": "",
"Created": "2018-10-16T05:21:13.292396576Z",
"Container": "a3083823beca98108c9b0239bd26453dba04d2ffd7aabb002e3c4d4ce26e0865",
"ContainerConfig": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8787/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/lib/rstudio-server/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"R_VERSION=3.5.1",
"LC_ALL=en_US.UTF-8",
"LANG=en_US.UTF-8",
"TERM=xterm",
"S6_VERSION=v1.21.4.0",
"S6_BEHAVIOUR_IF_STAGE2_FAILS=2"
],
"Cmd": [
"/bin/sh",
"-c",
"apt-get update -qq && apt-get -y --no-install-recommends install libxml2-dev libcairo2-dev libsqlite3-dev libmariadbd-dev libmariadb-client-lgpl-dev libpq-dev libssh2-1-dev unixodbc-dev && install2.r --error --deps TRUE tidyverse dplyr devtools formatR remotes selectr caTools BiocManager"
],
"ArgsEscaped": true,
"Image": "sha256:21494863674fd4db806d16b96ff96e35a960dae5883ecf73a9bb343584beb822",
"Volumes": {
"/home/rstudio/kitematic": {}
},
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"maintainer": "Carl Boettiger <[email protected]>",
"org.label-schema.license": "GPL-2.0",
"org.label-schema.vcs-url": "https://github.com/rocker-org/rocker-versioned",
"org.label-schema.vendor": "Rocker Project"
}
},
"DockerVersion": "18.03.1-ee-3",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8787/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/lib/rstudio-server/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"R_VERSION=3.5.1",
"LC_ALL=en_US.UTF-8",
"LANG=en_US.UTF-8",
"TERM=xterm",
"S6_VERSION=v1.21.4.0",
"S6_BEHAVIOUR_IF_STAGE2_FAILS=2"
],
"Cmd": [
"/init"
],
"ArgsEscaped": true,
"Image": "sha256:21494863674fd4db806d16b96ff96e35a960dae5883ecf73a9bb343584beb822",
"Volumes": {
"/home/rstudio/kitematic": {}
},
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"maintainer": "Carl Boettiger <[email protected]>",
"org.label-schema.license": "GPL-2.0",
"org.label-schema.vcs-url": "https://github.com/rocker-org/rocker-versioned",
"org.label-schema.vendor": "Rocker Project"
}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 1809809643,
"VirtualSize": 1809809643,
"GraphDriver": {
"Data": null,
"Name": "aufs"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:f715ed19c28b66943ac8bc12dbfb828e8394de2530bbaf1ecce906e748e4fdff",
"sha256:3f4e4e58bfe2eb291704c6d4f0290cbef16f186782c91874603b329f8b4fcdeb",
"sha256:3464d59c63ca738b514b2326b9ab5ae1f98ce1d745b0550c8ef8575dea82e468",
"sha256:361124d095ab256af24832a87dc2a8284093131f0883b139cce71880a2b4cbbb",
"sha256:d765234a779c9d92af39bdc0520bfffb0ccbcd7818fc22078b1fd6c6fedc4fd0",
"sha256:d04dffe8baa928e83dd2f27bf565178b9e05bcb32887c8cfdb13141d6bd16fee",
"sha256:f7f8979b332ebb6b415039d555c4a3d0e29977eb8b4686dafd057763e1efac41",
"sha256:32d792b4b56e294f7e75dd76f7d6f546881996231016a26835594aa6a9112824"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
What's my problem?
You have a permission problem on the folders you mention, they have an owner, which is not the same as the one you are running the Rstudio instance with docker under , hence the permissions error when saving. You can verify this by:
First an explanation of permissions, ownership and other topics: Understanding Basic File Permissions and ownership in Linux
As you commented, one of your folders throws this information:
The permission is quite common, it gives read, write and execute privileges to the owner of the folder and removes the ability to write to the rest of the users who are part of the same group as the owner or to the others (those who are not the owner or part of the owner's group).
Any user who is not the owner will be able to see the contents of the folder but will not be able to save anything in it. In this case, the owner is the super user
root
, something "strange" since in the casehome
of a userroot
one would not expect to see that the owner of the folders is the user himself, this makes me think that the creation of these folders made them directly theroot
Finally , it is worth saying that if you are
root
not you will not be able to save anything in these folders , it is not a docker problem, it is a permissions problem at the OS level, which you can verify simply by trying to create any content:~
is the alias ofhome
the active user. You should get an error similar to this:And how do we solve it?
It depends on what the system allows you to do, here are a series of options:
Work with a common user No
root
This is the best and usual in environments
linux
, when you enter the server, you do so through a user, which you can always consult throughwhoami
. Unless the installation is a catastrophe, you should be able to create new folders and they will inherit your ownership, so something like this should work:In this case we "mapped" the new folders to the volume names that you already handled, it does not necessarily have to be the same name of the physical folder. This should allow you to save to
ad_R
andad_data
.work directly as
root
It is not the best, but it is possible to start a session directly as
root
, it is rare, because your user and folderhome
is different, but if you want to continue using the folders already created, this is a way.(a). You can login directly as
root
and then go to the working folder, for example:cd /home/lab227
(b). You can start your session normally and then impersonate as
root
using the commandsu
, enter the password and that's it. Verify that you are indeed the superuser bywhoami
Either way, you are now the owner of the folders, you should start the docker instance as you do and have no more problems (at least this one).
(c) You can run a command from a common user, but, like
root
, for example, usingsudo
:And we can not change the ownership of the folders?
Yes, it is also possible but clearly it has to be done by the super user or the owner (in this case the same), you change the owner like this, in this case logged in as the common user :
In this case it
$USER
is the alias of the active user. You can then check the permissions, for example if your user islab227
:You should have an output like this:
As it looks, it is the minimum necessary that you will need so that the Rstudio instance started as
lab227
in docker can work. In fact, this is perhaps the simplest and the one you should try first.Files are owned by root and group root, does your program also run as root? I prefer to check the access permissions.
You can also run
docker inspect <volume_name>
to see if the volume is RW or RO and mounted correctly.