Created
December 1, 2016 09:22
-
-
Save jowave/9f9059cd79bd8e59398ac5f7fe7b6218 to your computer and use it in GitHub Desktop.
Reading ".env" in Vagrantfile to provide environment for docker-compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure(2) do |config| | |
if !Vagrant.has_plugin?("vagrant-docker-compose") | |
print " WARN: Missing plugin 'vagrant-docker-compose'.\n" | |
print " Use 'vagrant plugin install vagrant-docker-compose' to install.\n" | |
end | |
compose_env = Hash.new | |
if File.file?('.env') | |
# read lines "var=value" into hash | |
compose_env = Hash[*File.read('.env').split(/[=\n]+/)] | |
# ignore keys (lines) starting with # | |
compose_env.delete_if { |key, value| key.to_s.match(/^#.*/) } | |
end | |
config.vm.provision :docker | |
config.vm.provision :docker_compose, | |
project_name: "docker-vagrant", | |
yml: "/vagrant/docker-compose.yml", | |
env: compose_env, | |
run: "always" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I try my best to solve ,but it can’t be finished.
`==> default: bash: line 4: =: command not found
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
SOURCE_DIR=./www ='' DATA_DIR=./data TZ=Asia/Shanghai CONTAINER_PACKAGE_URL=mirrors.aliyun.com ALPINE_VERSION=3.12 NGINX_VERSION=1.19.1-alpine NGINX_HTTP_HOST_PORT=80 NGINX_HTTPS_HOST_PORT=443 NGINX_CONFD_DIR=./services/nginx/conf.d NGINX_CONF_FILE=./services/nginx/nginx.conf NGINX_FASTCGI_PHP_CONF=./services/nginx/fastcgi-php.conf NGINX_FASTCGI_PARAMS=./services/nginx/fastcgi_params NGINX_SSL_CERTIFICATE_DIR=./services/nginx/ssl NGINX_LOG_DIR=./logs/nginx NGINX_INSTALL_APPS='' PHP_VERSION=7.1.33 PHP_PHP_CONF_FILE=./services/php/php.ini PHP_FPM_CONF_FILE=./services/php/php-fpm.conf PHP_LOG_DIR=./logs/php PHP_EXTENSIONS=pdo_mysql,mysqli,mbstring,gd,curl,opcache,amqp,bcmath,bz2,calendar,exif,gettext,igbinary,mcrypt,mongodb,pcntl,pdo_pgsql,pgsql,rdkafka,redis,shmop,soap,sockets,ssh2,swoole,sysvmsg,sysvsem,sysvshm,wddx,xsl,yaf,zip MYSQL5_VERSION=5.7.28 MYSQL5_HOST_PORT=3305 MYSQL5_ROOT_PASSWORD=123456 MYSQL5_CONF_FILE=./services/mysql5/mysql.cnf REDIS_VERSION=5.0.3-alpine REDIS_HOST_PORT=6379 REDIS_CONF_FILE=./services/redis/redis.conf NODE_VERSION=10.16.1-alpine /usr/local/bin/docker-compose-1.29.2 -f "/vagrant/docker-compose.yml" up -d
Stdout from the command:
Stderr from the command:
bash: line 4: =: command not found`