cloning running servers with docker and criu by ross boucher

31
Cloning Running Servers Ross Boucher @boucher

Upload: docker-inc

Post on 15-Apr-2017

3.694 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Cloning Running Servers with Docker and CRIU by Ross Boucher

Cloning Running Servers

Ross Boucher@boucher

Page 2: Cloning Running Servers with Docker and CRIU by Ross Boucher
Page 3: Cloning Running Servers with Docker and CRIU by Ross Boucher

$ node>> 2 + 24>>

Browser Server

2 + 2

4

Page 4: Cloning Running Servers with Docker and CRIU by Ross Boucher

x = 1

1

++x

2

x == 2

true

[1]

[2]

[3]

x = 1

1

++x

2

x == 2

true

[4]

[2]

[3]

Page 5: Cloning Running Servers with Docker and CRIU by Ross Boucher
Page 6: Cloning Running Servers with Docker and CRIU by Ross Boucher

(Checkpoint Restore In Userspace)CRIU

Page 7: Cloning Running Servers with Docker and CRIU by Ross Boucher

CRIU+

Page 8: Cloning Running Servers with Docker and CRIU by Ross Boucher

Application Server

Evaluation Controller

Public Internet Internal Network Isolated Network

Container PoolUser’s Browser

Primary Docker Eval Docker

2 + 2

4

Page 9: Cloning Running Servers with Docker and CRIU by Ross Boucher

message: "evaluate" nodeVersion: "4.x.x" sources: [{ type: "source", text: "var x = 2 + 2", checksum: "a8efd" }] url: "/users/boucher/repositories/12345/branches/master"

2 + 2 Application Server

Page 10: Cloning Running Servers with Docker and CRIU by Ross Boucher

message: "get-evaluator" nodeVersion: "4.x.x" checksums: [ "a8efd" ] url: "/users/boucher/repositories/12345/branches/master"

2 + 2 Evaluation Controller

Application Server

Page 11: Cloning Running Servers with Docker and CRIU by Ross Boucher

function get_evaluator(configuration) { if (cached_containers[configuration]) {

return cached_containers[configuration] } if (checkpoint_exists(configuration)) {

return restored_container(configuration);}return pooled_container(configuration)

}

2 + 2Evaluation Controller

Page 12: Cloning Running Servers with Docker and CRIU by Ross Boucher

message: "found-evaluator" IP: "172.0.1.201" port: "7777"

Evaluation Controller

Application Server

Page 13: Cloning Running Servers with Docker and CRIU by Ross Boucher

message: "establish-connection" message: "get-source" index: 0

message: "source-at-index" index: 0

source: "var x = 2+2;" message: "output" value: 4

Application Server

Page 14: Cloning Running Servers with Docker and CRIU by Ross Boucher

message: "output" index: 0 value: 4

2 + 2 Application Server4

Page 15: Cloning Running Servers with Docker and CRIU by Ross Boucher

message: "checkpoint-evaluator" checksum: "a8efd" url: "/users/boucher/repositories/12345/branches/master"

2 + 2 Evaluation Controller

Application Server

Page 16: Cloning Running Servers with Docker and CRIU by Ross Boucher

await container.checkpoint({ LeaveRunning: true, ImagesDirectory: “/checkpoints/<document_id>/<checksum>/”})if (await container.changes().length > 0) {

metadata.image = await container.commit({ pause: false })}await fs.writeFile(metadata, “/checkpoints/<document_id>/<checksum>/metadata.txt”)

2 + 2Evaluation Controller

Page 17: Cloning Running Servers with Docker and CRIU by Ross Boucher

# current cli$ docker checkpoint --leave-running --image-dir=/checkpoint/path <container_id>

$ docker commit --pause=false <container_id>

# new cli$ docker checkpoint --exit=false <container_id> <checkpoint_id>

2 + 2Evaluation Controller

Page 18: Cloning Running Servers with Docker and CRIU by Ross Boucher

message: "get-source" ...

message: "source-at-index" ...

message: "finished" (process exited)

Application Server

Page 19: Cloning Running Servers with Docker and CRIU by Ross Boucher

message: "predict-evaluator" checksums: [ "a8efd" ] url: "/users/boucher/repositories/12345/branches/master"

2 + 2 Evaluation Controller

Application Server

Page 20: Cloning Running Servers with Docker and CRIU by Ross Boucher

function predict_evaluator(configuration) {var cpPath = “/checkpoints/<document_id>/<checksum>/”;var metadata = await fs.readFile(metadata, cpPath + “/metadata.txt”);var container = await docker.restore({ ImagesDirectory: cpPath ...});cached_containers[configuration] = container;

}

2 + 2Evaluation Controller

Page 21: Cloning Running Servers with Docker and CRIU by Ross Boucher

$ docker create tonic/worker<container_id>

# current cli$ docker restore --force —image-dir=/checkpoint/path <container_id>

# new cli$ docker start --checkpoint <checkpoint_id> <container_id>

2 + 2Evaluation Controller

Page 22: Cloning Running Servers with Docker and CRIU by Ross Boucher

message: "evaluate" nodeVersion: "4.x.x" sources: [ { type: "source", text: "var x = 2 + 2", checksum: "a8fed"}, { type: "source", text: "x++", checksum: "b9ccc" } ] url: "/users/boucher/repositories/12345/branches/master"

Application Server

2 + 2

4

x++

Page 23: Cloning Running Servers with Docker and CRIU by Ross Boucher

function get_evaluator(configuration) { if (cached_containers[configuration]) {

return cached_containers[configuration] } if (checkpoint_exists(configuration)) {

return restored_container(configuration);}return pooled_container(configuration)

}

2 + 2Evaluation Controller

Page 24: Cloning Running Servers with Docker and CRIU by Ross Boucher

• Drop any capabilities you don’t need

• Set CPU, memory, and network constraints

• User Namespaces

• Network Isolation

• Seccomp

Security Concerns

Page 25: Cloning Running Servers with Docker and CRIU by Ross Boucher

• AUFS errors

• CRIU failures

• Race conditions

• Zombie processes

• Docker daemon restarts

• Filesystem management

Security Concerns

Page 26: Cloning Running Servers with Docker and CRIU by Ross Boucher

github.com/boucher/dockworkerDockWorker

Page 27: Cloning Running Servers with Docker and CRIU by Ross Boucher
Page 28: Cloning Running Servers with Docker and CRIU by Ross Boucher
Page 29: Cloning Running Servers with Docker and CRIU by Ross Boucher

(and other potential use cases)Container Migration

Page 30: Cloning Running Servers with Docker and CRIU by Ross Boucher

! Pre-compiled Release (based on Docker 1.10)

! Checkpoint/Restore Pull Request

! Saied Kazemi’s Linux Plumber’s Talk

! CRIU Homepage

! DockerCon Doom Demo

! Tonic Blog on checkpoint/restore

! DockWorker on Github

! Using P.Haul with Docker

! DockerScript is a cool tool we use to manage our images

Further Reading

Page 31: Cloning Running Servers with Docker and CRIU by Ross Boucher

Thanks!@boucher • [email protected]