[英]Symfony 2 application on Vagrant + Docker
我正在嘗試在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,但我有一個simliar問題只是使用vagrant和symfony。 我必須在vagrant文件中配置日志和緩存目錄的權限,所以像這樣(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,所以也要仔細檢查。
我的解決方案 在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用戶運行。 它解決了我的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.