-
Notifications
You must be signed in to change notification settings - Fork 2k
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
WatchConfig() does not work inside container #920
Comments
I just tested on CentOS 7, also failed. |
The reason this happens is that viper sets a watch on the directory containing the file, not the file itself. In my case the solution was to mount the config directory instead of the file, but this won't work for everyone. |
I'm running into similar issue where I do the following: viper.AddConfigPath(".")
viper.SetConfigType("yaml")
// config.yaml
viper.SetConfigName("config")
// other.yaml
viper.SetConfigName("other")
// watch config
viper.OnConfigChange(func(e fsnotify.Event) {
// something
})
viper.WatchConfig() Viper isn't watching the main config ( |
In Dockerfile, add "RUN add bash" before COPY,Using the way of bash to change config.yml can finish viper watch the operation of update config.yml file When docker image is running. |
这个容器中如何才能成功监视配置文件? |
Hello all, are there already solutions for this? Or another workaround than to read out the config in intervals? |
I was looking at how to use WatchConfig and found this issue.
for my Dockerfile:
and docker-compose:
When I change the config file, it gets the new config... I put some logs to see if it works and it worked. As @kylrth said, may it have something with how you do the volume mount, to not mount the file, but the directory. |
@diegoclair Thanks for the suggested solution, I tried to do the same, but nothing works |
I had a similar problem, it was about the fact that I mounted a directory instead of a file (as inline docker volumes are black magic) Maybe updating the error to "file is a directory" can be useful for later debugs. |
viper version: v1.7.0
go version go1.14.3 darwin/amd64
OS version: MacOS 10.15.2
I am using WatchConfig() to do hot config job. I mount a config file to container, which is watching by the app. The expected behavior is, when I updated the config file, the app inside the container will feel about it. However, it failed in my test.
Here is how reproduce it:
(main.go)
(Dockerfile)
(docker-compose.yml)
The config.yaml mod set to 666.
After I build the docker image, and up the docker-compose, I edit the config.yaml file, and save it. The app inside the container does not feel it. I am sure that the inode of the config.yaml keeps the same both inside and outside the container, and the file is changed both inside and outside the container.
I am not sure whether this feature is used in a proper way, but I really have no idea about what is going on there. Much appreciated if someone can help me out.
The text was updated successfully, but these errors were encountered: