Example:
docker-compose up -d nginx web1
curl http://10.0.0.4
docker-compose exec web1 sh -c 'criu dump -t $(pidof python3) -j -D /mnt --tcp-established'
docker-compose up -d web2
curl http://10.0.0.4
| from flask import Flask | |
| app = Flask(__name__) | |
| @app.route('/') | |
| def hello(): | |
| return "Hello world!\n" | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=80) |
| version: "2.4" | |
| services: | |
| web1: | |
| privileged: true | |
| build: . | |
| expose: | |
| - "80" | |
| volumes: | |
| - "checkpoint:/mnt" | |
| networks: | |
| app_net: | |
| ipv4_address: 10.0.0.2 | |
| web2: | |
| command: criu restore -D /mnt --tcp-established | |
| privileged: true | |
| build: . | |
| expose: | |
| - "80" | |
| volumes: | |
| - "checkpoint:/mnt" | |
| networks: | |
| app_net: | |
| ipv4_address: 10.0.0.3 | |
| nginx: | |
| image: nginx:stable-alpine | |
| volumes: | |
| - ./nginx.conf:/etc/nginx/nginx.conf:ro | |
| ports: | |
| - "80:80" | |
| networks: | |
| app_net: | |
| ipv4_address: 10.0.0.4 | |
| networks: | |
| app_net: | |
| driver: bridge | |
| ipam: | |
| driver: default | |
| config: | |
| - subnet: 10.0.0.0/24 | |
| gateway: 10.0.0.1 | |
| volumes: | |
| checkpoint: |
| FROM ubuntu:18.04 as build | |
| RUN apt-get update -qq | |
| RUN apt-get install -qq \ | |
| libnet-dev \ | |
| libnl-route-3-dev \ | |
| gcc \ | |
| bsdmainutils \ | |
| build-essential \ | |
| git-core \ | |
| iptables \ | |
| libbsd-dev \ | |
| libaio-dev \ | |
| libcap-dev \ | |
| libgnutls28-dev \ | |
| libgnutls30 \ | |
| libnl-3-dev \ | |
| libprotobuf-c-dev \ | |
| libprotobuf-dev \ | |
| libselinux-dev \ | |
| pkg-config \ | |
| protobuf-c-compiler \ | |
| protobuf-compiler \ | |
| python3-minimal \ | |
| python3-distutils \ | |
| asciidoctor \ | |
| curl | |
| RUN git clone --depth 1 https://github.com/checkpoint-restore/criu/ /usr/src/criu \ | |
| && cd /usr/src/criu \ | |
| && make -j $(nproc) \ | |
| && make install PREFIX=/usr \ | |
| && rm -rf /usr/src/criu | |
| RUN apt-get install -qq python3-flask | |
| COPY app.py /app.py | |
| CMD python3 app.py |
| user nginx; | |
| worker_processes 1; | |
| error_log /var/log/nginx/error.log warn; | |
| pid /var/run/nginx.pid; | |
| events { | |
| worker_connections 1024; | |
| } | |
| http { | |
| upstream web { | |
| server 10.0.0.2:80; | |
| server 10.0.0.3:80; | |
| } | |
| server { | |
| listen 80; | |
| location / { | |
| proxy_pass http://web; | |
| } | |
| } | |
| } |