dockerapachedocker-compose

How to run Apache in docker container?


I am trying to run apache in docker container, but docker container exits with code 0 because after running apachectl start in container it runs in background so main process is finished, and docker stops container. How to start apache in interactive mode in bash?

Here is my Dockerfile

FROM ubuntu

RUN apt update -y && apt upgrade -y
RUN apt install -y apache2  php

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer

WORKDIR /var/www

CMD ["apachectl", "start"]

EXPOSE 80 443

And here is a fragment of my docker-compose.yml

 web-server:
    build: ./apache
    volumes:
      - ../src:/var/www
      - ./conf:/etc/apache2/sites-enabled
    ports:
      - "80:80"
      - "443:443"
    networks:
      - internal

after i'am doing docker compose up --build i see this

Container docker-web-server-1  Recreated 
web-server-1 exited with code 0

What is the *nix command to run Apache as a main process of container?


Solution

  • CMD ["apachectl", "-D", "FOREGROUND"]
    

    Try this. CMD ["apachectl", "start"] runs on background, docker needs process to run on foreground.