Docker Community Forums

Share and learn in the Docker community.

Unable to mount Host directory file(Volume) onto container's /var/log


(Sanjeevakn) #1

Requirement: I am trying to mount a volume from Host to a docker container(/var/log) so that all the log files for this particular container is written to the Host volume. The basic idea is to have all the logs written by the container instance is persisted and can be read.
I have a debian docker image running on Ubuntu 18.04

What I did:

  1. Create a folder /root/dockerlogs in the Host system
  2. Start the container using the below command

docker run -d -v /root/dockerlogs:/var/log debian

Ouput of “docker ps -a” after running the above command is as below:

CONTAINER ID IMAGE COMMAND STATUS
qbbaafffaab8 debian “bash” Exited (0) 2 minutes ago

Any idea or a workaround is appreciated.

Thanks,
Sanjeev


(David Maze) #2

Exit code 0 in Linux is generally “success”, so it worked!

…it doesn’t look like you told the container to actually anything. You’ve read the Docker tutorial on building and running custom images? The overall use case of using a host-mounted volume to get logs out is sound, but an uncustomized Debian image doesn’t actually run an application that would create interesting logs.


(Sanjeevakn) #3

Thanks dmaze.
Since the container exit, I am unable to get attached to the container for customizing the debain image. I would like to host a sample website in the container and write all the log files include apache log to Host.


(David Maze) #4

I’d highly recommend reading Docker’s official tutorial on building custom images. Getting an interactive shell to “customize” a container isn’t really a best practice: you’re at strong risk of losing your work when the container gets deleted, and of not remembering what exactly you did when you need to recreate the image a year from now.