Create Dockerfile with multiple services

Hello everyone i want to create a docker image with a dockerfile.
The docker image must run httpd and mariadb. From A centos 7 image.
My probleme Is when i run the image httpd start but mariadb not.
Can Anyone please help me.
Thanks,

My Dockerfile

#############################
FROM centos:7

MAINTAINER HAMZA_BENHAMANI

Install All Packages

RUN yum install -y mariadb-server httpd
CMD mysqld_safe
CMD apachectl -D FOREGROUND
#############################

A Dockerfile can only have one CMD instruction. Only the last will run and others will be ignored.

What most people do is run one service per container. So you would have a httpd container and a mariadb container communicating with each other through a shared network.

If you insist on running both in the same container, you have to start both services using a single CMD instruction.

1 Like

I want to run both in one container. How can i do it sir,