Run a bash script in docker-compose

I’m trying to bring up an OwnCloud container on my docker server via docker compose. I’m using the stock OwnCloud image from Docker Hub. Here is my yaml file:

version: '3.1'

services:

  owncloud:
    image: owncloud
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - '/etc/docker/owncloud/data:/var/www/html'
      - '/etc/docker/owncloud/ssl.sh:/etc/apache2/ssl.sh'
    networks:
        default:
            ipv4_address: 192.168.226.28
  mysql:
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ********
volumes:
    owncloud_data:
        driver: local
networks:
    default:
        external:
            name: pub_net

It works great. The container comes up and I can access it via http. Now of course I want to access via https so you can see bash script I’ve sent into my container. Here are the contents of that script:

#!/bin/bash
a2enmod ssl
a2ensite default-ssl
openssl req -x509 -nodes -days 99999 -newkey rsa:2048 -subj "/C=US/ST=Ohio/L=Cleveland/O=Data/CN=fake.domain.com" -keyout /etc/ssl/private/ssl-cert-snakeoil.key -out /etc/ssl/certs/ssl-cert-snakeoil.pem
service apache2 restart

Now, if I manually bash into the container and run that script it works great. I can access OwnCloud via https. Here’s where it get’s annoying. I want to automate the process of running that script so when the container updates its part of the rebuild process. So far I’ve tried adding a "command" string in the yaml file like this:

version: '3.1'

services:

  owncloud:
    image: owncloud
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - '/etc/docker/owncloud/data:/var/www/html'
      - '/etc/docker/owncloud/ssl.sh:/etc/apache2/ssl.sh'
    networks:
        default:
            ipv4_address: 192.168.226.28
    command: /etc/apache2/ssl.sh
  mysql:
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: mdluci84
volumes:
    owncloud_data:
        driver: local
networks:
    default:
        external:
            name: pub_net

When I run docker-compose up it does appear to run the script, except it runs it over and over again, and the apache service keeps restarting. Here is a snippet of the logs:

Restarting Apache httpd web server: apache2.

Considering dependency setenvif for ssl:

Module setenvif already enabled

Considering dependency mime for ssl:

Module mime already enabled

Considering dependency socache_shmcb for ssl:

Module socache_shmcb already enabled

dule ssl already enabled

Site default-ssl already enabled

Generating a RSA private key

…………….+++++

……………+++++

writing new private key to ‘/etc/ssl/private/ssl-cert-snakeoil.key’


AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 192.168.226.28. Set the ‘ServerName’ directive globally to suppress this message

[Wed Oct 07 21:09:05.504798 2020] [ssl:warn] [pid 33] AH01906: 192.168.226.28:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)

[Wed Oct 07 21:09:05.504883 2020] [ssl:warn] [pid 33] AH01909: 192.168.226.28:443:0 server certificate does NOT include an ID which matches the server name

Restarting Apache httpd web server: apache2.

Considering dependency setenvif for ssl:

Module setenvif already enabled

Considering dependency mime for ssl:

Module mime already enabled

Considering dependency socache_shmcb for ssl:

Module socache_shmcb already enabled

dule ssl already enabled

Site default-ssl already enabled

Generating a RSA private key

………………………………+++++

………………………….+++++

writing new private key to ‘/etc/ssl/private/ssl-cert-snakeoil.key’


AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 192.168.226.28. Set the ‘ServerName’ directive globally to suppress this message

[Wed Oct 07 21:09:15.145928 2020] [ssl:warn] [pid 33] AH01906: 192.168.226.28:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)

[Wed Oct 07 21:09:15.146014 2020] [ssl:warn] [pid 33] AH01909: 192.168.226.28:443:0 server certificate does NOT include an ID which matches the server name

Restarting Apache httpd web server: apache2.

Considering dependency setenvif for ssl:

Module setenvif already enabled

Considering dependency mime for ssl:

Module mime already enabled

Considering dependency socache_shmcb for ssl:

Module socache_shmcb already enabled

dule ssl already enabled

Site default-ssl already enabled

Generating a RSA private key

………………………+++++

……………………………………+++++

writing new private key to ‘/etc/ssl/private/ssl-cert-snakeoil.key’


AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 192.168.226.28. Set the ‘ServerName’ directive globally to suppress this message

[Wed Oct 07 21:09:29.712422 2020] [ssl:warn] [pid 33] AH01906: 192.168.226.28:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)

[Wed Oct 07 21:09:29.712500 2020] [ssl:warn] [pid 33] AH01909: 192.168.226.28:443:0 server certificate does NOT include an ID which matches the server name

I’m not sure where to go from here. Any ideas?

Source: Docker Questions