2

In my production environment production.rb. I have configured my log will be saved to file:

  config.logger = Logger.new('log/production.log')

When I run locally (start server by using command line rails s -e production). everything works fine. But when I run on docker environment, I don't see production.log printed out.

Please help me about this problem.

Trần Kim Dự
  • 5,872
  • 12
  • 55
  • 107

1 Answers1

2

I don't see production.log printed out.

Where are you looking? On your host or in the docker container that you are running?

By default, the file will be created in your container filesystem.
If you want it directly visible from your host (which runs the docker daemon), you would need to mount an host directory as a data volume first.

docker run -d -P --name myapp -v /a/local/host/path:/path/to/log/in/container myimage

Then you would see production.log in /a/local/host/path.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I checked in my container not in host. I put log file same directory with source code. – Trần Kim Dự Dec 28 '16 at 16:14
  • @TrầnKimDự How did you check in your container? Did you do a docket exec -it mycontainer bash? (http://stackoverflow.com/a/31580097/6309) – VonC Dec 28 '16 at 16:17
  • Yes. that's true. I run that command to go into my container's directory app. – Trần Kim Dự Dec 28 '16 at 16:21
  • @TrầnKimDự in that case, you need to debug your app in your container first: has it started successfully? Do you see it when you do a `ps -eaf`? Is there a right issue (no write access to write the logs), ... – VonC Dec 28 '16 at 16:26
  • My server started successfully. I'm thinking about permission too. How can I verify if a file can be written by a process ? thanks – Trần Kim Dự Dec 28 '16 at 18:31
  • @TrầnKimDự simply do a `ls -alrth` in the log folder, check its associated right and user: `rwxrwxr-x`? And compare that with the user running your app process (that you see with a `ps -eaf`) – VonC Dec 28 '16 at 19:33