Will the output of programs in docker (such as `print`) be saved to disk?

problem description

After the container in the

server has been running for several days, the disk is full. After looking for a large file, it is found that there is a very large file ending with log in the container folder under the / var/lib/docker path. Start the program after deletion, and check the directory
ix62tS.md.jpg

after half an hour.

the environmental background of the problems and what methods you have tried

the temporary solution at that time was to write a script to delete the log file on a regular basis.

There is only print output in the

code, and the log file is not saved.

then modify the code to remove the printout, and the log file no longer appears. I suspect that docker automatically collected these prints.

In the end, I"m not sure if the server disk is full because docker automatically collects these prints . Please give us some advice.

Nov.24,2021

your print should be saved in the docker log.

  • first check your log information to see if you can see the contents of print, and if so, output it to log.
sudo docker logs -f container_id
  • then take a look at the storage address of the corresponding log
sudo docker inspect container_id|grep log
  • View the address log_path, to view the corresponding size
sudo du -h log_path

after consulting the data, we know that:

  • all the logs above belong to the print golang of the standard output (stdout), python, and the fmt.Println of the print golang belongs to stdout;
  • The logging mechanism in

    docker is called a log driver;

    • each container is a special process created and started by docker daemon and guarded and managed by docker daemon, so docker daemon can get the stdout; of container
  • docker daemon has a default log driver, which defaults to json-file;

    • json-file writes the standard output and standard error of all containers to a file in json format. The file records one standard output or standard error per line and comments it with a timestamp.
  • change the default log launcher, as follows:

    • Edit docker deamon configuration file: sudo vim / etc/docker/daemon.json
    • add one item: {"log-driver": "none"} (you can also add {"log-opts": {"max-size": "10m"}} to control the size of the log file)
    • reload the configuration file and restart the docker service: sudo systemctl daemon-reload , sudo systemctl restart docker
    • restart the recognition task after modifying the configuration, and no log file is generated.

reference address:
Docker production environment log-JSON File log driver
configure log driver

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea8577-1ec8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea8577-1ec8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?