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

How can I get hot reloading work in docker? 🤗 #102

Open
hcancelik opened this issue Apr 24, 2022 · 5 comments
Open

How can I get hot reloading work in docker? 🤗 #102

hcancelik opened this issue Apr 24, 2022 · 5 comments
Labels
🤔 Question Further information is requested

Comments

@hcancelik
Copy link

Question description
I'm having trouble getting the hot reloading working with fiber dev inside a docker container.

Here is my Dockerfile.

FROM golang:1.18-alpine as build

WORKDIR /go/src/api

RUN go install github.com/gofiber/cli/fiber@latest

COPY . .

RUN go mod download

CMD ["fiber", "dev"]

Here is my docker-compose file.

services:
  db:
    image: mongo:5.0.7
    restart: always
    ports:
      - 27017:27017
    volumes:
      - mongodb:/data/db
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${DB_USERNAME:-root}
      MONGO_INITDB_ROOT_PASSWORD: ${DB_PASSWORD:-password}

  api:
    depends_on:
      - db
    build:
      context: ./api
      target: build
    restart: always
    ports:
      - 3000:3000
    volumes:
      - ./api:/app

volumes:
  mongodb:

I do see the files being changed inside the container but I cannot get the fiber cli to restart the fiber. What I might be missing?

Thanks.

@welcome
Copy link

welcome bot commented Apr 24, 2022

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@MohabMohamed
Copy link

@hcancelik I think the problem is you are mounting the wrong directory inside the container. you are mounting /app in the docker-compose file and putting your code in /go/src/api.

so try to change the docker file line WORKDIR /go/src/api to WORKDIR /app or change in your docker-compose.yml the part

    volumes:
      - ./api:/app

to

    volumes:
      - ./api:/go/src/api

both solutions should work, if it still not working please tell me.

@hcancelik
Copy link
Author

Thanks for the reply @MohabMohamed.

They are indeed wrong, so I've corrected them. However, the hot reload is still not working.

@TheTeaCat
Copy link

TheTeaCat commented Jul 26, 2022

I've had this issue today with an Ubuntu 22.04 machine, while the hot reloading works fine on a mac.

I'm pretty certain what this comes down to is the fact that file system events on the Ubuntu host machine don't get propagated into the container - if we go inside the container and modify the files from within then the hot reloading works, but if we modify it from the host machine it doesn't.

If the host machine is MacOS then changes on the host machine do trigger the hot reload as osxfs supports creation, modification, attribute change, deletion and directory change events. See the docs here.

This is an issue for non-mac users wanting to containerise their development environments face with various different development tools that provide hot reloading, and the typical solution is to provide a legacy watch option which periodically checks for changes instead of relying upon file system events. This CLI tool doesn't have one, though. Feature request maybe?

In the meantime I'm going to experiment with using air instead, which has been suggested in this comment in an issue on the gofiber/fiber repo regarding hot reload support.

@ReneWerner87 ReneWerner87 added the 🤔 Question Further information is requested label Jul 26, 2022
@TheTeaCat
Copy link

TheTeaCat commented Jul 26, 2022

Update: air also doesn't have a legacy watch option, so neither air or the fiber cli work in my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants