How do I run Apache 2 on Alpine in Docker?

According to Alpine wiki I have to run rc-service apache2 startafter installation of Apache 2. However, there’s no rc-service in the Alpine running inside the container. How do I get the service command to run inside Docker container?

  • cannot build docker image
  • Sh : file not found on alpine Docker image
  • How to substitute a command output into a string and append that to a file (in Alpine Linux running in Docker)
  • Can't install package on alpine though I can see it in the ui
  • is it possible to get remote ip by apache run in docker
  • How to get 'man' working in an Alpine Linux Docker container?
  • How to run a docker container if not already running
  • Monitoring Glassfish 4 on Docker with JVisualVM
  • Mysqladmin in mysql docker?
  • Docker for Windows: error pulling image configuration: i/o timeout
  • Vagrant, Docker, Puppet, Chef
  • Cassandra docker - unable to connect through JMX
  • 2 Solutions collect form web for “How do I run Apache 2 on Alpine in Docker?”

    gliderlabs/docker-alpine issue 183 illustrate the docker Alpine image has no service or rc-service.

    You can see instead nimmis/docker-alpine-apache based on nimmis/docker-alpine-micro, which includes a runit, used to handle starting and shutting down processes automatically started.

    That initd will start the apache2 script, which calls:

    exec /usr/sbin/httpd -D FOREGROUND -f /web/config/httpd.conf
    

    Alpine does not have rc-service installed by default. You need to install it (either as part of your Dockerfile build process or manually in the container).

    The secret invocation is:

    apk add openrc --no-cache
    

    If you want to run it from outside the container (say docker run), then use:

    docker run [options etc] bin/ash -c "apk add openrc --no-cache"
    

    PS: rc-service is good for other things and stuff like mariadb (also not included in alpine)

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.