# # Docker + Nginx systemd service # # Author: Artem Smirnov # Source: https://urpylka.com/posts/post-12/ # # This service aims to make http reverse proxy service # # To use: # 1. Create a Docker volume container named `webproxy-data`. # 2. Initialize the data container. # 3. Download this service file to /etc/systemd/service/docker-webproxy.service # 4. Enable and start the service template with: # `systemctl enable --now docker-webproxy.service` # 5. Verify service start-up with: # `systemctl status docker-webproxy.service` # `journalctl --unit docker-webproxy.service` # # For more information, see the systemd manual pages. # [Unit] Description=Nginx reverse proxy docker container Documentation=https://urpylka.com/posts/post-12/ After=network.target docker.service Requires=docker.service [Service] RestartSec=10 Restart=always Environment="NAME=webproxy" Environment="NGINX_CONF=/home/user/webproxy.conf" Environment="IMG=nginx:latest" Environment="PORT=80:80" Environment="COMMAND=/usr/sbin/nginx" Environment="ARGS=-g \"daemon off;\"" Environment="NETWORK=webproxy" # Clean-up bad state if still hanging around ExecStartPre=-/usr/bin/docker rm -f ${NAME} # Attempt to pull new image for security updates ExecStartPre=-/usr/bin/docker pull ${IMG} # Main process ExecStart=/usr/bin/docker run --rm --cap-add=NET_ADMIN \ --name ${NAME} \ --network=${NETWORK} \ -p ${PORT} \ -v ${NGINX_CONF}:/etc/nginx/conf.d/default.conf \ ${IMG} ${COMMAND} ${ARGS} [Install] WantedBy=multi-user.target