How do I use Vagrant Docker provider env attribute?

I want to change the environment variable of a docker container using Provender Provender. How can i do this?

Example Vagrantfile:

config.vm.define 'container' do |ws|
    ws.vm.hostname = 'container'
    ws.ssh.port = 23
    ws.ssh.guest_port = 23
    ws.vm.provider "docker" do |d|
      d.image = "name/image"
      d.env = {
        "SSH_PORT" => 23
      }
      d.vagrant_machine = "host"
      d.vagrant_vagrantfile = "../Vagrantfile"
      d.force_host_vm = true
      d.has_ssh = true
    end
end

      

Sample Dockerfile:

FROM centos:centos7
ENV PORT 22
#...
RUN echo "Port $PORT" >>  /somefile.txt
#...
EXPOSE $PORT

      

It always ends with PORT = 22 instead of 23. A possible workaround with d.create_args = ["-e", "PORT=23"]

also failed.

Sources: Vagrant Docker environment-vars

+3


source to share


2 answers


When you define ENV PORT 22

in yours Dockerfile

, it will be defined as such and not inherited from the build environment. If you want to override it, you can do it during the startup of the container: docker run --rm -it -e PORT=23 <your image> env | grep PORT

.



+1


source


Try to change the part d.env

:



d.env = {
        "SSH_PORT":"23"
}

      

+2


source







All Articles