Docker Community Forums

Share and learn in the Docker community.

Best Practices running docker container as daemon trouble


(Mrlindenwillow) #1

I have a node app, that is packaged into an executable.
When I run the executable from a docker build image, the container stopped right after start, even with -td like stackoverflow articles suggest.
I then added a bash script to run the application then tail -f thelogs.

this allows the container to stay running, but is this a hacky work around?
Is there a better way to make the container run, instead of tailing the log file?

Another best practice question, when i do a docker build, i have a few required scripts that install the application through the command line interface which requires COPY of the script and the .tar of the application.
I feel like if someone is going to use the Dockerfile they will need all the auxiliary scripts is kinda klunky.
Is there a better approach to getting the users the required files?
Is github the best way to accomplish this?
Thank you for your time and patience,
Happy docker explorer.


(David Maze) #2

Yes.

Fix the application so that it runs as a foreground process, not a daemon. It may already have a command-line option for this.

Put them all in the same source repository. It’s very common to put the Dockerfile in the root directory of the repository alongside your Makefile/Gemfile/setup.py/package.json/build.sbt/myapp.cabal file.

If you only need the scripts at build or install time, another approach is to build a tarball or some other artifact, either on the host or in a different Docker container, and then just ADD that tarball to your runtime image. This either requires some orchestration on the host, or a newer Docker that supports multi-stage builds (I do still see a fair number of posts here from users with older Dockers that don’t support it).

Maybe, depending on your needs. (You can run a private source control repository without it being in the cloud; IMHO there are far more usable source control systems than git; but if you don’t want to maintain it yourself and don’t mind it either being public or paying for it, GitHub is a fine choice.)


(Mrlindenwillow) #3

Thank you for the quick reply.
I am going to see if I can add an argument to make the application run in the foreground, to prevent any workarounds.

Of course! I see the Dockerfile in many repos, It should have occurred to me that I can provide the resources when they download the .tar of the application. Perfect.

Thank you for your diligence!
Z