Docker Community Forums

Share and learn in the Docker community.

How to run multiple services (apache2 and script file) from dockerfile?

Dear all,

I am using Ubuntu 18.04 as the base image and installed necessary packages for the same.

a. I want to run apache2 service from the root and I will move to user for starting the contianer. For this, I have used the command ,

USER root
RUN service apache2 start

USER user

But when I move to user later on, this apache2 service status stays not connected. How to stay it connected throughout in the user too.?

b. I also have .sh file which need to be run

The command used for .sh run file is:

USER root
WORKDIR /home/data/pvw/bin
RUN chmod +x

USER user
CMD [ "sh", "-c", "./;bash"] #sleep infinity

c. Finally, how to run both sh file along with apache2 service from the same dockerfile that works on user? (The sh file works on user, but not the apache2 service?)

d. I am new to docker, so if the framing of question is not correct, please correct me.

Sunag R A.


“RUN service apache2 start”, will not work correctly when spawning the container, neither does it make sense to have the this command (or the CMD apachectl -D FOREGROUND for that sake) in the dockerfile.

instead, remove the RUN and CMD, and move “apachectl -D FOREGROUND” into your script, and just start that.

The dockerfile is just “all you need to run this image” not “what i need + start it”
you start it when you create the container from this image