Service not started automatically in Docker container using Dockerfile

I am trying to run ansible playbook using Dockerfile playbook run fine and using Dockerfile but when i try to mention apache2 service to start using RUN service apache2 start in Dockerfile and try to run docker build . command the Dockerfile run successfully without error But when i login to container and check apache2 service it is in stopped mode.Everytime when i run docker build command it run successfully but when login to container service is in stop mode.

Please let me know what is the issue.

Thanks

Dockerfile’s purpose is creating an image only.

What you want is a container which has running apache2 service.

It’s different.

There are some solutions for your problems.
The simplest one is in your run command, append: service apache2 start. For example

docker run -d --name abc image/apache service apache2 start

Other solution is implement Entrypoint, you can refer to postgres Dockerfile to find more detail.

Hope this can help.