dokku - where is my application's directory
Asked Answered
S

2

7

I am trying to access logs of my Node.js application which is written in file mylogfile.log inside application's directory. Using find / -type f -name mylogfile.log i was able to see this output:

/var/lib/docker/aufs/diff/0303e86afdc58e13b5afcc07ea3694e0e9e6d5e5cf8530a0854a76fbe2baf574/app/mylogfile.log
/var/lib/docker/aufs/diff/a9a0dab44456acd8b43915ed686c282b778ab99df31f62076082e121274ef6e2/app/mylogfile.log
/var/lib/docker/aufs/mnt/0303e86afdc58e13b5afcc07ea3694e0e9e6d5e5cf8530a0854a76fbe2baf574/app/mylogfile.log   

What are those directories (if this is a previous app pushes, why do i even need them, i don't really want to flood hard drive's space with them) and which of those is a directory of my currently running app?

Also inside ...mnt/ and ...diff/ there is much more folders with similar cryptic names.

Skuld answered 5/5, 2015 at 17:54 Comment(0)
F
5

Please note that the filesystem of a Docker container is not intended to be accessed by users from the host. It's quite complicated actually, since Docker uses a layered copy-on-write filesystem (like AUFS in your case, but that's distribution-specific; most Distros except Ubuntu use Devicemapper instead of AUFS, IIRC). What you see there are filesystem layers, each one containing the difference to one parent layer.

If you want to log stuff inside your application container, you should consider one of the following possibilities:

  1. Put your log files into a volume. You can mount a host directory as a volume and write files in there. You need to specify mounts when creating the container, using the -v flag (-v <host-directory>:<dir in container>):

    docker run -v /var/log/myapplication:/path/to/app/in/container myimage
    
  2. Write your logs to stdout and let Docker worry about the logs. You can access the log (yes, it'll be just one big file) using

    docker logs <container-name>
    

    You'll also find the log file in your Docker runtime directory (usually /var/lib/docker) in /var/lib/docker/containers/<container-id>/<container-id>-json.log. This log file won't be rotated automatically however, so it might grow big.

  3. Use an external logging service to write log data to another location in your network. Typical candidates would be syslog (old-school) or setting up something like Logstash or Graylog.

Flume answered 5/5, 2015 at 21:20 Comment(4)
wow, there is more to it, than i thought, i found this logs, but now i am concerned with itheir size, I'm not deploying docker container manually, im using dokker, so what can i do to rotate them or limit their size, is there any inbuild tools for this? I was googling it, but yet with no noticable success. And i don't really want ot load my VPS by seting logstash container there...Skuld
If I understand correctly, you're in control of the application inside the container, correct? Simply write your logfiles not into the application directory, but in a separate directory that was created as volume. This can be a mounted host directory (then you can logrotate on the host); alternatively, you can mount your volume in another container and logrotate there. You could also just mount /dev/log into your container and use syslog to log into the host's syslog (haven't tried that, but should work).Flume
Yes i'm in control of the application, but not in control of deplyment itself (made automaticly by dokku), maybe i just misunderstood you, iam not so familliar with unix. I'm not fully understand what is volume yet (just a matter of some googling), yet i'm afraid that, while i am not creating a container manually, i'm unable to set mounts. I can create container manually, using docker, but its out of dokku's scope, and can (i suppose) be potentially conflicting with it. And as soon, as i will push app using dokku again - everything wiil be overriddenSkuld
Anyway i suppose there is no better way to answer my initial question. Will try to figure this out. Thank you for response.Skuld
N
4

@helmberts answer is great and gives you all you need, I try to give a tiny bit of salt to the dish (and something dokku- not docker-specific).

The point is, your app lives in a restorable on-off environment. With your deployment (git push) you kind of set up the ancester, everytime you start your app afterwords, you create a clone that dies once you stop the container (kind of).

You can do dokku run myapp ls / to see how it looks like. You could make changes (dokku run myapp touch /mytouched.file) but these are not persisted (dokku run gives you a fresh clone!) and "lost" immediately. If you want to have files somewhere forever, use a volume and mount it into you app-container(s). There is a cool plugin (dokku-volume) for that.

I cant tell you how to delete old diffs.

Noblenobleman answered 8/8, 2015 at 13:32 Comment(1)
thanks for this bit of "salt", and for pointing out this awesome plugin =)Skuld

© 2022 - 2024 — McMap. All rights reserved.