Welcome to FreeSoftwareServers Confluence Wiki

Note: I like to comment out the conf bind, start container, copy everything from container to "mnt" then outside container and then re-enable/restart.

WD=/opt/httpd
mkdir -p $WD/{setup,conf,html,logs,mnt}
cd $WD/setup
cat << 'EOF' >docker-compose.yaml
version: '3.7'

services:
 httpd:
    container_name: httpd
    image: httpd
    ports:
      - '8752:80'
    volumes:
      - type: bind
        source: /opt/httpd/conf/
        target: /usr/local/apache2/conf
      - type: bind
        source: /opt/httpd/html/
        target: /usr/local/apache2/htdocs
      - type: bind
        source: /opt/httpd/mnt/
        target: /mnt
      - type: bind
        source: /opt/httpd/logs/
        target: /var/log/apache2

    environment:
      - 'TZ=${TZ}'

EOF
chmod +x docker-compose.yaml

#systemctl restart httpd ; sleep 1 ; systemctl status httpd
cd $WD/setup
cat << 'EOF'>.env
TZ=America/Whitehorse
EOF
chmod +x .env
WD=/opt/httpd/setup
cat << EOF >$WD/httpd.service.setup.sh
cat << EOL >/lib/systemd/system/httpd.service
[Unit]
Description=httpd_Docker
Requires=docker.service network-online.target

[Service]  

WorkingDirectory=$WD
ExecStartPre=docker-compose pull
Restart=on-abnormal
ExecStart=/usr/bin/docker-compose --project-name httpd --project-directory $WD -f $WD/docker-compose.yaml up --force-recreate
ExecStop=/usr/bin/docker-compose --project-name httpd --project-directory $WD -f $WD/docker-compose.yaml stop

[Install]
WantedBy=multi-user.target
EOL
systemctl enable httpd
systemctl restart httpd
systemctl status httpd
EOF
chmod +x $WD/httpd.service.setup.sh
$WD/httpd.service.setup.sh
echo 'alias httpdcli="docker exec -it httpd /bin/bash"' >> ~/.bashrc
source ~/.bashrc
  • No labels