nflacco
nflacco

Reputation: 5082

Provisioning vagrant machine: The Dockerfile (Dockerfile) must be within the build context

I'm trying to build a docker container on the fly in a vagrant vm. The Vagrantfile and Dockerfile the container is to be built from are in the same directory, and on the VM, they are both found in the default synced folder /vagrant as expected. Unfortunately, building the container does not work- I get The Dockerfile (Dockerfile) must be within the build context. What is the proper build context in this case? Do I need to copy the Dockerfile somewhere to be able to use it?

Vagrantfile:

Vagrant.configure("2") do |config|
    config.vm.provider "virtualbox"
    config.vm.box = "ubuntu/trusty64"
    config.vm.hostname = "ubuntu"

    config.vm.network :private_network, ip: "192.168.0.200"
    config.ssh.forward_agent = true
    config.ssh.insert_key = false

    config.vm.provision "docker" do |d|
        d.build_image "/vagrant/Dockerfile"
        d.build_args = ['--tag "container"']
        d.run "container"
    end
end

Output:

$ vagrant provision
==> default: Running provisioner: docker...
==> default: Building Docker images...
==> default: -- Path: /vagrant/Dockerfile
==> default: stdin: is not a tty
==> default: The Dockerfile (Dockerfile) must be within the build context (/vagrant/Dockerfile)
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

docker build  /vagrant/Dockerfile

Stdout from the command:



Stderr from the command:

stdin: is not a tty
The Dockerfile (Dockerfile) must be within the build context (/vagrant/Dockerfile)

Upvotes: 0

Views: 1670

Answers (1)

SteveChapman
SteveChapman

Reputation: 3081

The d.build_image "/vagrant/Dockerfile" option should refer to the containing folder of the Dockerfile, in this case:

Vagrant.configure("2") do |config|
    config.vm.provider "virtualbox"
    config.vm.box = "ubuntu/trusty64"
    config.vm.hostname = "ubuntu"

    config.vm.network :private_network, ip: "192.168.0.200"
    config.ssh.forward_agent = true
    config.ssh.insert_key = false

    config.vm.provision "docker" do |d|
        d.build_image "/vagrant"
        d.build_args = ['--tag "container"']
        d.run "container"
    end
end

Upvotes: 1

Related Questions