strapi-docker icon indicating copy to clipboard operation
strapi-docker copied to clipboard

strapi image created under root user

Open Laazarus opened this issue 5 years ago • 12 comments

Hello, I am sorry if this is not a problem, it could be me being very expert on strapi (I am evaluating it for a project I have to start) and Docker ( i have used it only a couple of times).

When I run docker-compose up command everything goes well and the environment get set up and run fine my only problem is that the strapi app folder and the db folder are created under the root ownership making it impossible to be opened on an IDE such us Visual studio code in order to modify the project (e.g it is impossible to install a new file uploader provider if not from inside the container).

Again this might me me having done something wrong but I have tried everything and I canot find a solution.

I am running under Linux Ubuntu 18.0.4 docker is not running with sudo but under a docker group which my own user belongs too.

I really appreciate you help and thanks for this repo :)

Regards

Laazarus avatar Mar 28 '19 16:03 Laazarus

“Running a Docker container as a non-root user” by Lucas Wilson-Richter https://link.medium.com/19C6L1OTxV

But I agree. This should be fixed as all files are mounted

FDiskas avatar Apr 02 '19 00:04 FDiskas

Thanks I am trying a bit everything but I could not still figure out a way to make thing fully working. After the creation I change the owner of the volume in the host machine using this command sudo chown -R $USER This seems to work fine the only issue I am having is the host folder the strapi folder under npm module is not present. This is a problem because i I want to install aws file upload or any other plug in for strapi I have to install it inside the container.

Is this expected?

Is anywhere a procedure I can follow to install the image in the correct way?

Thanks again for your support and for this image :)

Laazarus avatar Apr 03 '19 10:04 Laazarus

HI,

We just released a full rebuild of our docker image 🎉 We are closing the issues and open PRs to start fresh.

If you feel like something is missing or want to add things feel free to open new PRs ! 💯

alexandrebodin avatar Oct 23 '19 08:10 alexandrebodin

This issue is not resolved :( Please see #263

guicara avatar Dec 29 '20 21:12 guicara

Reopening the original issue and closing the duplicate one #263.

If someone wants to help out on this topic let me know.

Until we find a fix, I would recommend you create a custom Dockerfile and set it up how you actually want it.

alexandrebodin avatar Dec 30 '20 14:12 alexandrebodin

I think I discovered the problem:

this commit added the line to the strapi/strapi Dockerfile: RUN mkdir /srv/app && chown 1000:1000 /srv/app.

However the first command mkdir fails because /srv/app already exists and therefore chown is never executed, so the contents of /srv/app stays owned by the root user.

I still don't understand why this didn't happen when I used the docker-compose instructions for a two container app (strapi and postgres or strapi and mongo).

EDIT: Nevermind the above, I think the problem is actually in the strapi new command in the dockerentrypoint.sh script. The script is executed under root permissions and I think it deletes and recreates the srv/app dir, meaning that the directory is recreated with the owner as root, negating what was done in the Dockerfile to change the permissions. This is a deeper problem than I thought.

nckdhl avatar Feb 24 '21 17:02 nckdhl

Any updates on what could be done to fix this? I've set the UID:GID using docker-compose as mentioned earlier, but it seems it is still the case that strapi new is run with root priviledges, because I cannot access /srv/app and get the following error

Using strapi 3.5.4
No project found at /srv/app. Creating a new strapi project
Creating a new Strapi application at /srv/app.
Creating a project from the database CLI arguments.
Creating files.
[Error: EACCES: permission denied, rmdir '/srv/app'] {
errno: -13
code: 'EACCES',
syscall: 'rmdir',
path:

Edit: after a bit of experimenting and viewing strapi/Dockerfile, it seems a fix was attempted to recursively change ownership of srv/app, but I believe the reason it doesn't work is subsequent files placed in this directory are still created/owned by root. The ownership needs to be changed after all the files are created, at least in my head that would be the solution.

RussellSanders1 avatar Apr 21 '21 15:04 RussellSanders1

temporary solution, @RussellSanders1

it is important that the folder is created by the host, first create the application folder, Ex: app .

if the folder is created by the docker, it will complain about the permissions.

run the command below to find out your user id

id -u

change or add your user id to the user parameter in docker-compose.yml Ex: user: 1000:1000

in my case "user:group" would be 1000:1000

Ex:

version: '3'
services:
  strapi:
    image: strapi/strapi
    environment:
      DATABASE_CLIENT: postgres
      DATABASE_NAME: strapi
      DATABASE_HOST: postgres
      DATABASE_PORT: 5432
      DATABASE_USERNAME: strapi
      DATABASE_PASSWORD: strapi
    user: 1000:1000
    volumes:
      - ./app:/srv/app
    ports:
      - '1337:1337'
    depends_on:
      - postgres

  postgres:
    image: postgres
    environment:
      POSTGRES_DB: strapi
      POSTGRES_USER: strapi
      POSTGRES_PASSWORD: strapi
    volumes:
      - ./data:/var/lib/postgresql/data

run

docker-compose up

lucasnasm avatar May 20 '21 23:05 lucasnasm

did this got fixed? i'm trying to run it and the same error over and over again pops up image

lucaoskaique avatar Feb 23 '22 23:02 lucaoskaique

I was able to fix it using docker and beanstalk.Sent from Android deviceOn 23 Feb 2022 23:23, Lucas Kaíque @.***> wrote: did this got fixed? i'm trying to run it and the same error over and over again pops up

—Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>

Laazarus avatar Feb 24 '22 08:02 Laazarus

Not working with any suggestions above..

Strapi uses root as @nckdhl explained This is stil a issue

image

luizwhite avatar Mar 07 '22 01:03 luizwhite

Not working with any suggestions above..

Strapi uses root as @nckdhl explained This is stil a issue

image

what i did was to change ownership from DATA folder, but i agreed it still is a issue

lucaoskaique avatar Mar 07 '22 12:03 lucaoskaique