在Vagrant + Docker上的Symfony 2应用程序

我正在尝试在Vagrant + Docker上部署Symfony 2应用程序。

Vagrantfile:

VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "ubuntu/precise64" # config.vm.synced_folder ".", "/vagrant", owner: 'web', group: 'web' config.vm.network "forwarded_port", host: 5000, guest: 80 # config.vm.network "forwarded_port", host: 5001, guest: 3306 config.vm.provision "docker" do |d| d.build_image "/vagrant/Docker", args: "-t site/web" d.run "site/web", args: "-p 80:80 -v /vagrant/application:/var/www/site" end end 

Dockerfile:

 FROM ubuntu:precise MAINTAINER umbrella-web <http://umbrella-web.com/> ENV DEBIAN_FRONTEND noninteractive WORKDIR / RUN echo "web:x:web:web::/home/web:/bin/bash" >> /etc/passwd RUN echo "web:x:web:" >> /etc/group # policy-rc.d access execution of start RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d # Update repositories RUN apt-get update -y && \ apt-get install python-software-properties -y && \ # add-apt-repository ppa:ondrej/apache2 -y && \ add-apt-repository ppa:ondrej/php5-oldstable -y && \ apt-get update -y && \ apt-get upgrade -y # isntall packages RUN apt-get update -y && \ apt-get -y install \ apache2 \ php5 \ php5-mysql \ libapache2-mod-php5 \ rpl \ # phpmyadmin \ php-apc \ # debug packages curl \ nano # Enable apache mods. # RUN a2enmod php5 RUN a2enmod rewrite RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf RUN /etc/init.d/apache2 restart ADD apache/www /var/www/site ADD apache/default /etc/apache2/sites-available/default # RUN touch /var/www/site/index.html # RUN echo "Hello!!!" /var/www/site/index.html RUN chown -R www-data:www-data /var/www/site USER web EXPOSE 80 # CMD /usr/sbin/apache2ctl -D FOREGROUND CMD bash 

Vagrantfile和Dockerv工作良好。 但是,我在Symfony 2 config.php文件中遇到了大问题。

 Change the permissions of either "app/cache/" or "var/cache/" directory so that the web server can write into it. Change the permissions of either "app/logs/" or "var/logs/" directory so that the web server can write into it. 

因为在docker集装箱项目文件所有者1001.谁是这个人?

 -rw-rw-r-- 1 1001 1001 1065 Oct 6 13:55 LICENSE -rw-rw-r-- 1 1001 1001 5732 Oct 6 13:55 README.md -rw-rw-r-- 1 1001 1001 1308 Oct 6 13:55 UPGRADE-2.2.md -rw-rw-r-- 1 1001 1001 1962 Oct 6 13:55 UPGRADE-2.3.md -rw-rw-r-- 1 1001 1001 356 Oct 6 13:55 UPGRADE-2.4.md -rw-rw-r-- 1 1001 1001 8499 Oct 6 13:55 UPGRADE.md drwxrwxr-x 1 1001 1001 4096 Nov 17 20:44 app drwxrwxr-x 1 1001 1001 4096 Nov 17 20:43 bin -rw-rw-r-- 1 1001 1001 2416 Oct 6 13:55 composer.json -rw-rw-r-- 1 1001 1001 56835 Nov 17 20:43 composer.lock -rw-r--r-- 1 1001 1001 19 Nov 20 13:49 index.php drwxrwxr-x 1 1001 1001 4096 Nov 17 21:33 nbproject drwxrwxr-x 1 1001 1001 4096 Nov 17 20:43 src drwxrwxr-x 1 1001 1001 4096 Nov 17 20:44 vendor drwxrwxr-x 1 1001 1001 4096 Nov 20 13:44 web 

我该如何解决这个问题? 命令chown和setfacl不工作…

我没有使用docker的stream浪汉,但是我只是使用了vagrant和symfony而已经有了一个类似的问题。 我必须在vagrant文​​件中configuration日志和caching目录的权限,所以像这样(guest是Ubuntu 14.04):

 config.vm.synced_folder "symfony/app/cache", "/vagrant/symfony/app/cache", owner: "www-data", group: "vagrant", mount_options: ["dmode=775,fmode=664"] config.vm.synced_folder "symfony/app/logs", "/vagrant/symfony/app/logs", owner: "www-data", group: "vagrant", mount_options: ["dmode=775,fmode=664"] 

这改变了这些目录的权限,但就像我说的,我不知道如何使用docker以及它们。 无论如何,这是值得的。

我还要提一下,根据你的symfony版本,目录可能是/ var / logs和/ var / cache,所以仔细检查一下。

我的解决scheme 在Dockerfile中我添加了这个:

 RUN echo "1001:x:1001:1001::/home/1001:/bin/bash" >> /etc/passwd RUN echo "1001:x:1001:" >> /etc/group 

和这个:

 RUN echo "User 1001" >> /etc/apache2/httpd.conf RUN echo "Group 1001" >> /etc/apache2/httpd.conf 

Nginx和php-fpm代表1001用户运行。 它解决了我的问题。