[lxc-devel] [lxd/master] implement a docker profile

hallyn on Github lxc-bot at linuxcontainers.org
Sat Feb 27 00:40:39 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 461 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160227/2b03e523/attachment.bin>
-------------- next part --------------
From f1faa563c9bc6d2a409b5d28d0daf61f7ff0a45e Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Date: Fri, 26 Feb 2016 16:07:48 -0800
Subject: [PATCH] implement a docker profile

so that you can easily launch a container in which you can run docker.

Thanks stgraber for the idea.

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 README.md          |  9 +++++++++
 lxd/db.go          |  7 ++++++-
 lxd/db_profiles.go | 24 ++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 5ef61c1..2ccbbb3 100644
--- a/README.md
+++ b/README.md
@@ -273,3 +273,12 @@ Yes. The easiest way to do that is using a privileged container:
 
     lxc launch ubuntu priv -c security.privileged=true
     lxc config device add priv homedir disk source=/home/$USER path=/home/ubuntu
+
+#### How can I run docker inside a LXD container?
+
+Create a container with the migrateable profile:
+
+	lxc launch ubuntu:xenial my-docker-host -p default -p docker
+
+Then run a version of docker with the needed patches, for instance version
+v1.10.0.serge.2 branch of github.com/hallyn/docker.
diff --git a/lxd/db.go b/lxd/db.go
index c4f6cf5..2938306 100644
--- a/lxd/db.go
+++ b/lxd/db.go
@@ -181,7 +181,12 @@ func createDb(db *sql.DB) (err error) {
 		}
 	}
 
-	return dbProfileCreateDefault(db)
+	err = dbProfileCreateDefault(db)
+	if err != nil {
+		return err
+	}
+
+	return dbProfileCreateDocker(db)
 }
 
 func dbGetSchema(db *sql.DB) (v int) {
diff --git a/lxd/db_profiles.go b/lxd/db_profiles.go
index 78cfbad..94c69ed 100644
--- a/lxd/db_profiles.go
+++ b/lxd/db_profiles.go
@@ -110,6 +110,30 @@ func dbProfileCreateDefault(db *sql.DB) error {
 	return nil
 }
 
+func dbProfileCreateDocker(db *sql.DB) error {
+	id, err := dbProfileID(db, "docker")
+	if err != nil {
+		return err
+	}
+
+	if id != -1 {
+		// docker profile already exists
+		return nil
+	}
+
+	config := map[string]string{
+		"security.nesting":     "true",
+		"linux.kernel_modules": "overlay, nf_nat",}
+	fusedev := map[string]string {
+		 "path": "/dev/fuse",
+		 "type": "unix-char",
+	}
+	devices := map[string]shared.Device{ "fuse": fusedev, }
+
+	 _, err = dbProfileCreate(db, "docker", config, devices)
+	return err
+}
+
 // Get the profile configuration map from the DB
 func dbProfileConfig(db *sql.DB, name string) (map[string]string, error) {
 	var key, value string


More information about the lxc-devel mailing list