Mikhail Shchedrakov
Mikhail Shchedrakov

Reputation: 470

Symfony 2 application on Vagrant + Docker

i'm trying to deploy Symfony 2 application on Vagrant + Docker bunch.

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 and Dockerv works good. BUT, I have major problem in Symfony 2 config.php file.

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.

Because in docker container project files owner 1001. Who is this guy?

-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

How i can resolve this problem? Command chown and setfacl not work...

Upvotes: 4

Views: 1323

Answers (2)

Mikhail Shchedrakov
Mikhail Shchedrakov

Reputation: 470

My solution. In Dockerfile i added this:

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

And this:

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

Nginx and php-fpm is running on behalf of 1001 user. it solved my problem.

Upvotes: 3

Sehael
Sehael

Reputation: 3736

I haven't used vagrant with docker, but I have had a simliar issue just using vagrant and symfony. I had to configure the permissions for the logs and cache dirs in the vagrant file, so something like this (guest is 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"]

This changes the permissions for those directories, but like I said, I am not sure how it will all work using docker as well. It's worth a shot anyways.

I should also mention, depending on your symfony version, the directories might be /var/logs and /var/cache, so double check that as well.

Upvotes: 3

Related Questions