We all know, once the main process in any given container stops running, well, our container stops as well and every log goes with it. Well, creating a volume might just be solution.
What happens when we have a container that ‘fails’ and we don’t really have a way to know why such thing happen since now that our container is dead, well, logs and everything else have died as well.
A nice way to approach this problem is to create a local host volume to store our container(s) log files for any given application, for this example we are using NGINX.
Example & Solution — Volume Creation
Let’s say we have a custom Nginx image that is giving us problems and dies after an ‘X’ amount of time and we have no way to know what is happening since we can’t access such logs, well, let’s create a local host volume that will include every Nginx log file!
First, we need to create the container with such volume path:
docker run --name webserver -d -P -v /containers/logs/nginx:/var/log/nginx nginx
- –name webserver is optional… You can provide any name you like or none
- -P is so we can have a network port to access our nginx container
- -v will create a local /containers/logs/nginx folder in the host
Now, we can easily access such logs:
cd /containers/logs/nginx && ls
We should see access.log and error.log
Now, figure out the problem and keep on working! 🙂