Skip to content
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

Watcher not working in a docker container if user is not root #1592

Open
e-gloo opened this issue Apr 15, 2024 · 1 comment
Open

Watcher not working in a docker container if user is not root #1592

e-gloo opened this issue Apr 15, 2024 · 1 comment
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@e-gloo
Copy link

e-gloo commented Apr 15, 2024

Hello,
I am running a task with a watcher inside a docker container to reload te server when any file changes. While everything was working when the user was root, now that I change the user inside my dockerfile, the watcher doesn't seem to work anymore. Moreover, when nothing has changed and I run the container, the task says that everything is up to date and won't run the cmd.
Here's my task:

  run-server:
    watch: true
    deps: [build]
    sources:
      - '**/*.go'
      - 'web/templates/**/*.templ'
      - exclude: 'web/templates/**/*_templ.go'
      - exclude: 'internal/pkg/repositories/*.gen.go'
      - exclude: 'internal/pkg/repositories/*.sql.go'
    cmds:
      - ./out/server

My dockerfile:

FROM golang:1.22.1-alpine

ARG USER_ID
ARG GROUP_ID

RUN apk add --no-cache curl git
#
# RUN addgroup --gid ${GROUP_ID} app &&\
#     adduser --uid ${USER_ID} --ingroup app --disabled-password app
#
# USER app

WORKDIR /app

RUN go install github.com/go-task/task/v3/cmd/task@latest

RUN git config --global --add safe.directory /app

# COPY --chown=app:app go.mod go.sum ./
COPY go.mod go.sum ./

RUN go mod download && go mod verify

# COPY --chown=app:app . .
COPY . .

EXPOSE 8080

CMD ["/go/bin/task", "-s", "run-server"]

And my docker compose

services:
  tt-app:
    container_name: tt-app
    build:
      context: .
      dockerfile: Dockerfile
      args:
          USER_ID: ${USER_ID:-0}
          GROUP_ID: ${GROUP_ID:-0}
    ports:
      - "8080:8080"
    volumes:
      - ./:/app

In this configuration, everything works fine, but as soon as I uncomment/replace the lines in my dockerfile, rebuild and run, the watcher doesn't work anymore. I need to be able to run the container as the same user as the host so when I generate files from the container I can edit them (without having to chown each file generated).
Thank you!

  • Task version: v3.35.1 (h1:zjQ3tLv+LIStDDTzOQx8F97NE/8FSTanjZuwgy/hwro=)
  • Operating system: Arch Linux x86_64 / Kernel: 6.8.5-arch1-1
  • Experiments enabled: No
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Apr 15, 2024
@trulede
Copy link

trulede commented May 31, 2024

You may need to change the owner of WORKDIR in your dockerfile.

WORKDIR /app
RUN chown app:app/app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

3 participants