Skip to content

Failed to run docker container #1270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hibare opened this issue Jan 12, 2020 · 20 comments
Closed

Failed to run docker container #1270

hibare opened this issue Jan 12, 2020 · 20 comments
Assignees
Labels
bug Something isn't working docs Documentation related

Comments

@hibare
Copy link

hibare commented Jan 12, 2020

Getting following error when try to run docker command specified in README.md file.

error EACCES: permission denied, mkdir '/home/coder/.local/share/code-server/extensions'

Tried on elementary os and on actual UBUNTU server

@sr229 sr229 added the bug Something isn't working label Jan 12, 2020
@realthk
Copy link

realthk commented Jan 12, 2020

Same here. Seems the reccommended Docker command from the readme

docker run -it -p 127.0.0.1:8080:8080 -v "${HOME}/.local/share/code-server:/home/coder/.local/share/code-server" -v "$PWD:/home/coder/project" codercom/code-server:v2

creates ~/.local/share/code-server folder with root user and drwxr-xr-x, so no other user can write into it.

Therefore a simple solution is

sudo chown $USER ~/.local/share/code-server/

@githubsaturn
Copy link

githubsaturn commented Jan 13, 2020

Why this is happening:
This is the result of unnecessary result of user demotion in the Dockerfile:
https://github.com/cdr/code-server/blob/master/Dockerfile#L45

When the source directory doesn't exist, Docker automatically creates it and the "owner" will be the root user. Due to the user demotion mentioned above, code-server isn't able to put any content inside that folder.

I'd like to ask maintainers of code-server to fix this, as this is definitely an annoying problem because it simply prevents users to use simple named volumes.

Solutions:
1- Why do we demote the user to a non-root inside the container? There is nothing inside the container that it's accessible by root but not the non-root. It only cause problems.

2- Change the CMD script such that it checks if the permissions isn't correct, it sudo changes it.

I am happy to help out with this.

The main benefit of using Docker is portability, but this permission assumption breaks the portability principal of Docker containers.

@githubsaturn
Copy link

As you can see this issue has been encountered by many users:
#1243
#992
#673
#1188
and many more.

@demyxco
Copy link

demyxco commented Jan 13, 2020

The simplest fix would be to create the directories before switching user. If you look at their Dockerfile at lines 48-50, it's being created as root without chowning to the coder user.

Scratch what I said, I didn't read between the lines. code-server works fine if using named volumes but if you use bind mounts (aka mount a directory from host to container), then that directory has to be chowned by uid:guid 1000.

@sr229
Copy link
Contributor

sr229 commented Jan 13, 2020

Why this is happening:
This is the result of unnecessary result of user demotion in the Dockerfile:
https://github.com/cdr/code-server/blob/master/Dockerfile#L45

When the source directory doesn't exist, Docker automatically creates it and the "owner" will be the root user. Due to the user demotion mentioned above, code-server isn't able to put any content inside that folder.

This is incorrect. whatever runs in USER will run anything in below it as the user. The reason of this is because the bind mounted folder has a different permission scheme than in the container. This is why we'll need to add chmod -R g+rw in the project mount folder (which was multiple times were rejected, but I'll be taking over the Dockerfile maintenance from now on).

Solutions:
1- Why do we demote the user to a non-root inside the container? There is nothing inside the container that it's accessible by root but not the non-root. It only cause problems.

This will create a "close to a real environment" scenario for beginning users. Not everyone has done Linux/Unix before so we should teach them best practices - and that starts with that root is always dangerous to use if you're ignorant of how powerful the superuser account is. This also increases compatibility with Kubernetes and OpenShift - which enforces user-only containers. This is considered best practices.

@githubsaturn
Copy link

This is incorrect. whatever runs in USER will run anything in below it as the user. The reason of this is because the bind mounted folder has a different permission scheme than in the container. This is why we'll need to add chmod -R g+rw in the project mount folder (which was multiple times were rejected, but I'll be taking over the Dockerfile maintenance from now on).

It's not incorrect. Remove the line that highlighted and things work fine.

Regardless, offloading the responsibility of fine tuning the directory permissions to the user in Docker environment isn't considered a fix.

With regards to root user, I agree. But any dangerous action, should be contained within the container. Having said that, it'd be suboptimal solution. It'd be better to fix the root cause which is the permission for the directory.

@sr229
Copy link
Contributor

sr229 commented Jan 13, 2020

@githubsaturn this is considered BAD practice. It might not be for you but it is bad practice.

This is not a fix, we know it works already but the problem is the permissions we need to apply to the folder, because even if we own them, the bindmounted folder inheirts the host folder's permissions.

We're not discussing about this any further. Whether you like it or not, your solution is NOT a solution. This is non-compliant and is considered insecure.

@githubsaturn
Copy link

You misread what I said:

Having said that, it'd be suboptimal solution. It'd be better to fix the root cause which is the permission for the directory.

@code-asher
Copy link
Member

code-asher commented Jan 13, 2020 via email

@code-asher
Copy link
Member

code-asher commented Jan 13, 2020 via email

@hibare
Copy link
Author

hibare commented Jan 18, 2020

What would be the best workaround to get the container up and running?

@code-asher
Copy link
Member

code-asher commented Jan 21, 2020 via email

@sandercuppen
Copy link

I tried 2.1698, and it works fine for me, with named volumes.
Before, with named volumes or bind mounts i had permission issues.

@haliliceylan
Copy link

@code-asher
image
another error...

@sr229
Copy link
Contributor

sr229 commented Jan 25, 2020

@code-asher
image
another error...

It does not show the full extent of the error.

@nhooyr
Copy link
Contributor

nhooyr commented Jan 26, 2020

Given the amount of people that have had this issue, I think we need a FAQ entry on what exactly is going on. I'll dedicate some time tomorrow.

@sr229 sr229 added the docs Documentation related label Jan 26, 2020
@sr229
Copy link
Contributor

sr229 commented Jan 26, 2020

Marking as docs.

@haliliceylan
Copy link

@code-asher
image
another error...

It does not show the full extent of the error.

There is no other error output on my console.

@nhooyr
Copy link
Contributor

nhooyr commented Jan 27, 2020

So we need to get rid of -v from the docker command since it doesn't make sense as the container runs as uid 1000 but the cache directory is created as root by default.

I think it's fine if the container command we advertise keeps the cache in the container so its sandboxed but we ought to have a FAQ entry to document where code-server keeps its state.

@nhooyr nhooyr closed this as completed in a674d88 Jan 27, 2020
@sthulb
Copy link

sthulb commented Jan 30, 2020

@code-asher
image
another error...

It does not show the full extent of the error.

There is no other error output on my console.

I think this is a different issue! I've been trying to run the latest binary on an Ubuntu EC2 instance and receive the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docs Documentation related
Projects
None yet
Development

No branches or pull requests

10 participants