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