Steven, John,

John, thank you for jumping in. I agree it's the proper solution.

I believe the reason why the first container immediately stops is
because, in docker, a container will be alive until the main process
(or entrypoint) is alive. For the pmacctd container, the entry point
is:

https://github.com/pmacct/pmacct/blob/master/docker/pmacctd/Dockerfile#L11

When using the daemonize option (in pmacctd, not in docker), the main
process will fork and the child process will detach from the parent,
so that the main process can exit the and leave the daemon process
running in background, pmacctd in this case ([1]). Of course this
makes docker realise the entrypoint process has finalised, and
therefore stops the container.

John's explanation on docker's -d option is spot on (reference:
https://docs.docker.com/engine/reference/run/#detached-vs-foreground).
Btw, something you might want to look into when using -d, docker
(daemon) can restart the container, automatically, based on the reason
why the container stopped, so called restart-policies:

https://docs.docker.com/engine/reference/run/#restart-policies---restart

Regards
Marc

[1]
https://github.com/pmacct/pmacct/blob/master/src/pmacctd.c#L613
https://github.com/pmacct/pmacct/blob/master/src/util.c#L95

Missatge de John Jensen <jense...@gmail.com> del dia dv., 1 d’oct.
2021 a les 19:28:
>
> Hey Steve,
>
> It is the proper solution.
>
> To add some context, if you don't pass '-it' (-i keeps STDIN open on the 
> container and -t allocates a pseudo-TTY and attaches it to the STDIN of the 
> container) or '-d' (which spawns the container in 'detached' mode, which will 
> return your running container ID) to 'docker run', it defaults to running 
> your container in 'foreground mode'. When you ran your first docker command, 
> did you get presented with essentially nothing until you killed the container 
> with ctrl+c? I believe the default in foreground mode is to attach the host's 
> STDIN/STDOUT/STDERR to that of the container, so if you essentially "saw 
> nothing" then I would have expected you to see pmacct running in 'ps' output 
> in a different shell on the same box.
>
> The second 'docker run' command works because you're overriding the 
> entrypoint of the container at runtime to /bin/bash (as well as specifying 
> -it to 'docker run'), which would drop you to a bash shell inside the 
> container, where you can manually invoke pmacct.
>
> You'll almost always see processes run inside of containers (ie pmacct, 
> webservers, etc) configured to run in the foreground by convention, because 
> you're already daemonizing/detaching "up a level" when you pass the -d flag 
> to 'docker run' - this allows the process running inside of the container to 
> send logs to STDOUT/STDERR which you can then look at by running the 'docker 
> logs <container_name_or_id>' command.
>
> HTH
>
> -JJ
>
> On Fri, Oct 1, 2021 at 12:29 PM Steve Clark <scl...@netwolves.com> wrote:
>>
>> Hi,
>>
>> I found if I set daemonize: false in my pmacctd.conf file and use the -d 
>> flag on the docker run line it seems to work.
>>
>> Don't know if this is the proper solution though.
>>
>> Thanks,
>> Steve
>>
>> On 10/1/21 7:21 AM, Steve Clark wrote:
>> > Hello,
>> >
>> >
>> > I am having trouble getting the "latest" or "bleeding-edge" docker image 
>> > to run by using the following command:
>> > docker run --privileged --network host -v 
>> > /etc/pmacct_netwolves/pmacctd.conf:/etc/pmacct/pmacctd.conf 
>> > pmacct/pmacctd:bleeding-edge
>> > $ docker ps
>> > CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS NAMES
>> > Fri Oct  1 07:15:37 EDT 2021
>> >
>> > but if I run the following command and then inside the container I run 
>> > pmaccd -f /etc/pmacct/pmacctd - it works
>> > docker run -it --privileged --network host -v 
>> > /etc/pmacct_netwolves/pmacctd.conf:/etc/pmacct/pmacctd.conf --entrypoint 
>> > /bin/bash  pmacct/pmacctd:bleeding-edge
>> >
>> > from another login on the same system
>> > V990002:~
>> > $ docker ps
>> > CONTAINER ID   IMAGE                          COMMAND CREATED          
>> > STATUS          PORTS     NAMES
>> > d4b0beab1b0b   pmacct/pmacctd:bleeding-edge   "/bin/bash"   46 seconds ago 
>> >   Up 45 seconds             silly_volhard
>> > Fri Oct  1 07:17:53 EDT 2021
>> > V990002:~
>> > $ ps awx|grep pmacct
>> > 18718 pts/1    Sl+    0:00 docker run -it --privileged --network host -v 
>> > /etc/pmacct_netwolves/pmacctd.conf:/etc/pmacct/pmacctd.conf --entrypoint 
>> > /bin/bash pmacct/pmacctd:bleeding-edge
>> > 18853 ?        Ss     0:02 pmacctd: Core Process [default]
>> > 18856 ?        S      0:00 pmacctd: Netflow Probe Plugin [eth1]
>> > 19348 pts/2    S+     0:00 grep --color=auto pmacct
>> >
>> > My system is CentOS 7.
>> > docker-ce-20.10.8-3.el7.x86_64
>> >
>> > Also I must add I am docker noobie.
>> > Email Confidentiality Notice: The information contained in this 
>> > transmission may contain privileged and confidential and/or protected 
>> > health information (PHI) and may be subject to protection under the law, 
>> > including the Health Insurance Portability and Accountability Act of 1996, 
>> > as amended (HIPAA). This transmission is intended for the sole use of the 
>> > individual or entity to whom it is addressed. If you are not the intended 
>> > recipient, you are notified that any use, dissemination, distribution, 
>> > printing or copying of this transmission is strictly prohibited and may 
>> > subject you to criminal or civil penalties. If you have received this 
>> > transmission in error, please contact the sender immediately and delete 
>> > this email and any attachments from any computer. Vaso Corporation and its 
>> > subsidiary companies are not responsible for data leaks that result from 
>> > email messages received that contain privileged and confidential and/or 
>> > protected health information (PHI).
>> >
>> > _______________________________________________
>> > pmacct-discussion mailing list
>> > http://www.pmacct.net/#mailinglists
>>
>> Email Confidentiality Notice: The information contained in this transmission 
>> may contain privileged and confidential and/or protected health information 
>> (PHI) and may be subject to protection under the law, including the Health 
>> Insurance Portability and Accountability Act of 1996, as amended (HIPAA). 
>> This transmission is intended for the sole use of the individual or entity 
>> to whom it is addressed. If you are not the intended recipient, you are 
>> notified that any use, dissemination, distribution, printing or copying of 
>> this transmission is strictly prohibited and may subject you to criminal or 
>> civil penalties. If you have received this transmission in error, please 
>> contact the sender immediately and delete this email and any attachments 
>> from any computer. Vaso Corporation and its subsidiary companies are not 
>> responsible for data leaks that result from email messages received that 
>> contain privileged and confidential and/or protected health information 
>> (PHI).
>>
>> _______________________________________________
>> pmacct-discussion mailing list
>> http://www.pmacct.net/#mailinglists
>
> _______________________________________________
> pmacct-discussion mailing list
> http://www.pmacct.net/#mailinglists

_______________________________________________
pmacct-discussion mailing list
http://www.pmacct.net/#mailinglists

Reply via email to