Home > database >  why `docker run -d centos tail -f /dev/null` command can keep the docker container running in the ba
why `docker run -d centos tail -f /dev/null` command can keep the docker container running in the ba

Time:10-08

enter image description here

This evening, by checking the data, I learned that to make the docker container run in the background, you should add tail - f /dev/null after the command. However, I don't understand the meaning of each letter in the command tail - f /dev/null. I only know that it can make the docker container run in the background. I want to know the meaning of each letter in the command tail - f /dev/null,Thanks in advance.

CodePudding user response:

there is an typo in your command. Remove the whitespace between - and f then it should work.

tail is responsible to read the last 10 lines of a file -f parameter means follow all lines which will be added to the file.

This is the reason why the terminal will stay open.

/dev/null is an linux device.

BR Sebastian

CodePudding user response:

I think you mean tail -f /dev/null

From man tail:

DESCRIPTION
       Print the last 10 lines of each FILE to standard output.
.
.
.
-f, --follow[={name|descriptor}]
          output appended data as the file grows;

          an absent option argument means 'descriptor'

/dev/null is a virtual device file that will appear to tail as if it were a "normal" file.

In plain English, this will make tail keep waiting for new data in /dev/null, but there will never be any since it's a special type of device (essentially a black hole).

  • Related