Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i persist my logs/data to local filesystem in docker

have an application running inside docker container. the application writes log messages into local log files. how can i make the log file persistent in case the docker container stops or crashes?

Since the container are run time entity ,when i stop the image my logs/data is gone.

Thanks, Sohan

like image 450
Sohan Avatar asked Dec 14 '22 18:12

Sohan


1 Answers

You can do this using docker volumes:

https://docs.docker.com/userguide/dockervolumes/

For example:

docker run -v /var/log/docker:/var/log your-image

will mount the log directory on your local file system. You can also get much fancier, creating containers just for data. It's all explained in the above link.

like image 161
seanmcl Avatar answered Mar 23 '23 18:03

seanmcl