4

I'm trying to have my container log into /var/log/app, a directory on the host machine. Unfortunately, changes made in the container are not being persisted, for example:

1 - start a container

sudo docker run -v /var/log/app --entrypoint bash -t -i b18bf31c48d5

2 - echo some file

echo "foo" > /varlog/app/foo.txt

3 - exit the container

4 - go check /var/log/app for foo.txt

it's not there.

Any idea why this happens?

Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232

1 Answers1

3

The problem was with the -v flag, this seems to make it work:

sudo docker run -v /var/log/app:/var/log/app:rw --entrypoint bash -t -i b18bf31c48d5

Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
  • It's not accurate to say it was a problem with the `-v` flag; that simply maps your docker volumes. You cannot pass just a path to the `-v` flag, you must also map that path to a location on your host if you want to view those log files outside the container. The path on the left is the directory inside your container and the path to the right of the colon is the path on your host. – Developer Dave Sep 13 '16 at 21:07
  • 4
    I think the path on the left side of the colon is the path on the host, and the path on the right of the colon is the path in the container. – Stephane Apr 15 '17 at 17:54
  • 2
    @Stephane You are right, the path on the left side on colon is the path on host directory. See [refrence](https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-host-directory-as-a-data-volume) – Prashant Prabhakar Singh May 10 '17 at 07:55