@@ -80,15 +80,25 @@ ebbrt::NodeAllocator::DockerContainer::~DockerContainer() {
8080 }
8181}
8282
83+ std::string ebbrt::NodeAllocator::DockerContainer::GetIp () {
84+ auto cip = RunCmd (" docker inspect -f '{{range "
85+ " .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' " +
86+ cid_ );
87+ assert (cip != " " );
88+ return cip;
89+ }
90+
8391std::string ebbrt::NodeAllocator::DockerContainer::Start () {
8492 if (!cid_.empty () || img_.size () == 0 ) {
8593 throw std::runtime_error (" Error: attempt to start unspecified container " );
8694 }
8795 std::stringstream cmd;
88- cmd << " docker run -d " << arg_ << " " << img_ << " " << cmd_;
96+ cmd << base_ << " run -d " << arg_ << " " << img_ << " " << cmd_;
8997 cid_ = RunCmd (cmd.str ());
9098 std::cerr << " Docker Container:" << std::endl;
91- std::cerr << " | img:" << img_ << std::endl;
99+ if ( host_ != " " ){
100+ std::cerr << " | host:" << host_ << std::endl;
101+ }
92102 std::cerr << " | cid: " << cid_.substr (0 , 12 ) << std::endl;
93103 std::cerr << " | log: docker logs " << cid_.substr (0 , 12 ) << std::endl;
94104 return cid_;
@@ -255,14 +265,11 @@ ebbrt::NodeAllocator::AllocateNode(std::string binary_path,
255265 std::to_string (allocation_id);
256266 std::stringstream docker_args;
257267 std::stringstream qemu_args;
268+
258269#ifndef NDEBUG
259270 docker_args << " --expose 1234 -e DEBUG=true" ;
260271#endif
261272
262- if (!args.constraint_node .empty ()) {
263- docker_args << " -e constraint:node==" << args.constraint_node << " " ;
264- }
265-
266273 if (CustomNetworkNodeArguments.empty ()) {
267274 docker_args << " --net=" << network_id_ << " " ;
268275 } else {
@@ -287,30 +294,27 @@ ebbrt::NodeAllocator::AllocateNode(std::string binary_path,
287294 << " -append \" " << cmdline_ << " ;allocid=" << allocation_id
288295 << " \" " ;
289296
290- auto c = DockerContainer (repo, docker_args.str (), qemu_args.str ());
297+ auto c = DockerContainer (repo, docker_args.str (), qemu_args.str (), args. constraint_node );
291298 auto id = c.Start ();
299+ auto cip = c.GetIp (); /* get IP of container */
292300
293301 nodes_.insert (std::make_pair (std::string (id), std::move (c)));
294302 auto rfut = promise_map_[allocation_id].GetFuture ();
295303
296- /* get IP of container */
297- auto cip = RunCmd (" docker inspect -f '{{range "
298- " .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' " +
299- id);
300- assert (id != " " );
301-
302304 /* transfer image into container */
303305 RunCmd (" ping -c 3 -w 30 " + cip);
304306 RunCmd (" nc -z -w 30 " + cip + " 22" );
305- RunCmd (" scp -q -o UserKnownHostsFile=/dev/null -o "
307+ RunCmd (" scp -q -o UserKnownHostsFile=/dev/null -o "
306308 " StrictHostKeyChecking=no " +
307309 binary_path + " root@" + cip + " :/root/img.elf" );
308310 /* kick start vm */
309- RunCmd (" docker exec -dt " + id + " touch /tmp/signal" );
311+ RunCmd (" ssh -q -o UserKnownHostsFile=/dev/null -o "
312+ " StrictHostKeyChecking=no root@" +cip+" 'touch /tmp/signal'" );
310313
311314 std::cerr << " Node Allocation Details: " << std::endl;
312315 std::cerr << " | img: " << binary_path << std::endl;
313316 std::cerr << " | id: " << container_name << std::endl;
317+ std::cerr << " | ip: " << cip << std::endl;
314318#ifndef NDEBUG
315319 std::cerr << " # debug w/ gdb: " << std::endl;
316320 std::cerr << " # gdb " << binary_path.substr (0 , binary_path.size () - 2 )
0 commit comments