0

I'm trying to write a deployable data science environment that runs the continuumio/anaconda3 Docker container within a ubuntu/trusty64 Vagrant box. This seems to run fine however the container shuts down immediately. Following the docs here I've tried passing the d.run and d.cmd commands to no success. I'd like to be able to do the Vagrant equivalent of passing the Docker command

docker run -i -t -p 8888:8888 continuumio/anaconda3 /bin/bash -c "/opt/conda/bin/conda install jupyter -y --quiet && mkdir /opt/notebooks && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip='*' --port=8888 --no-browser"

so that I can access the notebook from localhost:8888 (I've already done something similar with Apache httpd by following this guide). Unfortunately I just can't seem to get the syntax right for this, any help would be appreciated.

I have included my HostVagrantfile and Vagrantfile below.

HostVagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Specify Vagrant version, Vagrant API version, and Vagrant clone location
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"

# Create and configure the VM(s)
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Use Docker provisioner
  config.vm.provision "docker"

  # Workaround
  config.vm.provision "shell", inline:
     "ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill"

  # Assign a friendly name to this host VM
  config.vm.hostname = "docker"

  config.vm.box = 'ubuntu/trusty64'

  config.vm.network "forwarded_port", guest: 8888, host: 8888

  config.vm.synced_folder ".", "/vagrant"
end

Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Specify Vagrant version and Vagrant API version
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'

# Create and configure the Docker container(s)
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.define "apache" do |a|

    a.vm.provider "docker" do |d|

      d.image = "continuumio/anaconda3"
      d.name = "anacond3-container"
      d.ports = ["80:80", "433:443", "8888:8888"]
      d.remains_running = true
      d.vagrant_vagrantfile = "HostVagrantfile"
    end
  end
end

Update This is the result I get when trying to run:

$ vagrant docker-run -i -t -p 8888:8888 continuumio/anaconda3 /bin/bash -c "/opt/conda/bin/conda install jupyter -y --quiet && mkdir /opt/notebooks && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip='*' --port=8888 --no-browser"

An invalid option was specified. The help for this command
is available below.

Usage: vagrant docker-run [command...]

Options:

        --[no-]detach                Run in the background
    -t, --[no-]tty                   Allocate a pty
    -r, --[no-]rm,                   Remove container after execution
    -h, --help                       Print this help
jhole89
  • 718
  • 9
  • 28
  • did you try to run `vagrant docker-run -it apache -p 8888:8888 continuumio/anaconda3 -- /bin/bash -c "/opt/conda/bin/conda install jupyter -y --quiet && mkdir /opt/notebooks && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip='*' --port=8888 --no-browser"` – Frederic Henri Sep 26 '16 at 10:42
  • I've updated the question with the output of this – jhole89 Sep 28 '16 at 20:55

1 Answers1

0

Managed to work it out myself in the end. Needed to break the docker run command

docker run -i -t -p 8888:8888 continuumio/anaconda3 /bin/bash -c "/opt/conda/bin/conda install jupyter -y --quiet && mkdir /opt/notebooks && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip='*' --port=8888 --no-browser"

using the vagrant docker run, args, cmd commands after pulling the images. Instead of using

config.vm.provider "docker" do |d|
  d.image = "continuumio/anaconda3"
end

use

config.vm.provision "docker" do |d|
  d.pull_images "continuumio/anaconda3"
  d.run "continuumio/anaconda3",
    args: "-t -p 8888:8888",
    cmd: $jupyterServer
end

and define

$jupyterServer = <<SCRIPT
/bin/bash -c "/opt/conda/bin/conda install jupyter -y --quiet && mkdir /opt/notebooks && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip='*' --port=8888 --no-browser"
SCRIPT

I also combined the two Vagrantfiles into one:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Specify Vagrant version, Vagrant API version
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"

$jupyterServer = <<SCRIPT
/bin/bash -c "/opt/conda/bin/conda install jupyter -y --quiet && mkdir /opt/notebooks && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip='*' --port=8888 --no-browser"
SCRIPT

# Create and configure the VM(s)
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "ubuntu/trusty64"

  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--memory", "2048"]
    vb.customize ["modifyvm", :id, "--cpus", "2"]
  end

  # Use Docker provisioner
  config.vm.provision "docker" do |d|
    d.pull_images "continuumio/anaconda3"
    d.run "continuumio/anaconda3",
      args: "-t -p 8888:8888",
      cmd: $jupyterServer
  end

  config.vm.network "forwarded_port", guest: 8888, host: 8888
  config.vm.synced_folder ".", "/vagrant"
end
jhole89
  • 718
  • 9
  • 28