diff --git a/docker-compile-and-run/docker-compile-and-run.cpp b/docker-compile-and-run/docker-compile-and-run.cpp
index 2c6970cd374b67b96fb26078db53816706a698e3..586193d775d17826dd35f20fdd1db54d6a073eb6 100644
--- a/docker-compile-and-run/docker-compile-and-run.cpp
+++ b/docker-compile-and-run/docker-compile-and-run.cpp
@@ -21,7 +21,7 @@ string compile_and_run = "compile-and-run.sh";
 string bin_dir = "/home/wims/other/bin/";
 //string bin_dir = "";
 string docker = "/usr/bin/docker";
-bool verbose = false;
+bool verbose = true;
 
 void usage () {
     cerr << "docker-compile-and-run [program.cpp]" << endl;
@@ -63,7 +63,7 @@ int my_system(string cmd, const vector<string> args, const string in, const stri
             fclose(f);
         }
         if ( out != "" ) {
-            FILE* f = fopen(in.c_str(), "w");
+            FILE* f = fopen(out.c_str(), "w");
             dup2(fileno(f), STDOUT_FILENO);
             fclose(f);
         }
@@ -120,7 +120,18 @@ std::string my_popen(const string cmd, vector<string> args) {
 }
 
 string docker_run(string container, string cmd, vector<string> args) {
-    vector<string> docker_args = {"run", "-d", container, cmd};
+    // See http://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources
+    // for the resource limitations
+    vector<string> docker_args = {"run",
+                                  "--detach=true", // Run in background
+                                  // With 10M, the compilation and run is much slower
+                                  "--memory", "100M", "--memory-swap", "-1",
+                                  // Not available with docker 1.7?
+                                  // "--kernel-memory", "50M",
+                                  // "--cpu-quota" "50000", // Allow for using max 50% of the CPU
+                                  // Incompatible with detach
+                                  // "--rm=true", // Automatically delete container when done with the command
+                                  container, cmd};
     for (unsigned int i=0; i<args.size(); i++)
         docker_args.push_back(args[i]);
     string ID = my_popen(docker, docker_args);
@@ -160,11 +171,16 @@ int main(int argc, char **argv) {
     }
 
     string program=argv[1];
+    if (verbose)
+        cerr << "Compiling and running: " << program << endl;
     string program_in_docker="prog.cpp";
 
-    string docker_id = docker_run("crosbymichael/build-essential", "sleep", vector<string>({"1000"}));
-    if (verbose)
+    string docker_id = docker_run("crosbymichael/build-essential", "sleep", vector<string>({"10"}));
+    if (verbose) {
         cerr << "docker_id: " << docker_id << endl;
+        cerr << "Current directory: ";
+        my_system("/bin/pwd", {});
+    }
     docker_cp(docker_id, bin_dir+compile_and_run, compile_and_run);
     docker_cp(docker_id, program, program_in_docker);
     docker_exec(docker_id, vector<string>({ "chmod", "700", compile_and_run }));