1

I'm quite new to Docker, so maybe the answer to my question is obvious for you, sorry for that. I have a Docker container and I would like to save logs from it to the file so that they will be available even after removing the container.

I know I can access the logs of the container when it's running, but in case of removing the container, I would like to have a backup.

Probably I can redirect the logs to the file manually, but I would like to do that automatically in the real-time.

Is there any way to do that? I was looking for the answer but haven't found anything, although the problem sounds quite simple so I guess there is some solution to it.

Shayan Shafiq
  • 1,447
  • 5
  • 18
  • 25
Natalia
  • 375
  • 3
  • 11

1 Answers1

0

You can use volumes to do that. Here you can check the documentation from the official site.

If you are using docker-compose you can add a volume to your service like that:

services:
    mysql:
        image: mysql:5.6
        container_name: mysql
        volumes:
             - .docker/data/db:/var/lib/mysql
        ports:
             - 3306:3306

Now the files under your project dir .docker/data/db will be shared with Docker directory /var/lib/mysql

Carles
  • 180
  • 2
  • 12