Skip to main content

- Defending Internet Freedom

- IndieHosters

- Give Docker Trainings

- libre.sh, yet another Docker PaaS

- Meteor Freelancer

- ToS;DR

- IndieWeb

- I have something to Hide and you?

- Framasoft

indiehosters.net

github.com/IndiePaaS/IndiePaaS

twitter.com/pierreozoux

github.com/pierreozoux

tosdr.org/

pierre-o.fr

www.humancoders.com/formations/docker

www.meetup.com/Internet-Freedom-Lisbon/

ihavesomethingtohi.de/

framadrive.org

pierre@ozoux.net

Pierre Ozoux

Testing socket activation with docker-compose

1 min read

A simple test following this setup: https://developer.atlassian.com/blog/2015/03/docker-systemd-socket-activation/

cd /etc/systemd/system
ls test*
 # we need 3 unit-files
test-proxy.service  test-proxy.socket  test@.service

cat test-proxy.socket
[Socket]
ListenStream=8080

[Install]
WantedBy=sockets.target

cat test-proxy.service
[Unit]
Requires=test@test.indie.host.service
After=test@test.indie.host.service

[Service]
ExecStart=/lib/systemd/systemd-socket-proxyd 127.0.0.1:8081

cat test@.service
[Unit]

# Requirements
Requires=docker.service

# Dependency ordering
After=docker.service

[Service]
Restart=always
RestartSec=10
TimeoutStartSec=60
TimeoutStopSec=15
EnvironmentFile=/data/domains/%i/.env
WorkingDirectory=/data/domains/%i/
ExecStartPre=-/opt/bin/docker-compose rm -f
ExecStart=/opt/bin/docker-compose up
ExecStartPost=/opt/bin/waitport 127.0.0.1 8081
ExecStop=/opt/bin/docker-compose stop

cat /opt/bin/waitport
#!/bin/bash

host=$1
port=$2
tries=600

for i in `seq $tries`; do
    if ncat $host $port > /dev/null ; then
      # Ready
      sleep 1
      exit 0
    fi

    /bin/sleep 0.1
done

# FAIL
exit -1

 the docker-compose based from: https://github.com/indiehosters/static:
cat /data/domains/test.indie.host/docker-compose.yml
web:
  image: nginx
  volumes:
    - ./nginx.conf:/etc/nginx/nginx.conf:ro
    - ./data:/var/www/html
  ports:
    - "8081:80"

And here is the result! gif