Docker Community Forums

Share and learn in the Docker community.

How to build a container that runs a service

Hi there,

I’m tring to build my first contair and I looking for the best approach to do that.
My containar should run only one service.

On linux environment, the service is installed running a bash script that perfom the installation.

I created a docker file that do these things:

  • ADD the installation tar file
  • COPY and entrypoint script
  • RUN the entrypoint.

The entrypoint script:

  • Check if the service is already installed,
  • Otherwise install the serivice

My questions are:

  • Is this the correct approach to buil a container? O should I first install the service on my pc and than copy into the containter?
  • After the installation and every time I run the container, the container stop immediatly because the process run in background.

Thnaks in advance for the help.

Best regards.


Without knowing that much about your project, best practice is not running a service in docker, instead you should spawn the application, that the service would start, to run in the foreground.

Docker team recommends to use cross-platform built-in restart policy for running container as a service. For this, configure your docker service to start on system boot and simply add parameter --restart unless-stopped to the docker run command that starts YouTrack.