Code Monkey home page Code Monkey logo

docker-symfony's Introduction

Docker + Symfony

Docker boilerplate configuration for Symfony projects with fast NFS volumes on MacOS.

Features

  • Supports Linux and MacOS
  • Automatically configures NFS exports on MacOS if needed
  • No other dependencies required than Docker
  • Requires no configuration for developers
  • Easy to use for team members not familiar with Docker
  • Docker images contains cron, composer and supervisord (check out https://github.com/MDobak/php-common-stack for more)

Contents

Requirements

  • Docker Engine 1.13.0+
  • Docker Compose 1.10.0+
  • Docker For Mac 18.03.0-ce-mac60+ (for Mac OS only)
  • El Capitan 10.11+ (for Mac OS only)

Installation

Creating new project

  1. Change the PROJECT_NAME variable in both .env-linux.dev and .env-macos.dev files if you are working on multiple projects to avoid name collisions. You can also change other variables depending on your needs.
  2. Set correct paths in .env-*.dev files if you want to use different location than the /app directory.
  3. Make sure, that APP_PATH directory is empty.
  4. Execute ./console create-project symfony/website-skeleton 4.* to install project using composer`s create-project command. You can use different package name and version.

Migrating existing project

  1. Change the PROJECT_NAME variable in both .env-linux.dev and .env-macos.dev files if you are working on multiple projects to avoid name collisions. You can also change other variables depending on your needs.
  2. Copy all project files to desired location. By default all project files should be placed in the /app directory.
  3. Set correct paths in .env-*.dev files if you want to use different location than the /app directory.
  4. Start containers using ./console start command.
  5. If necessary, you can log in into container's shell using ./console shell php command.

File permissions on MacOS

On MacOS Docker uses NFS for volume mounting. By default NFS exports are mounted with the UID and GID of the currently running user on the Mac and it is not possible to change permissions and ownership of these files. Although, despite of UID and GID your containers will have access to these files.

Performance tips for MacOS

Cache directory

Shared volumes, even with NFS can be slow so its good idea to move as much data as possible outside shared directories. The easiest way is to move cache to the /tmp directory. To do it in Symfony you need to override the Kernel::getCacheDir method in your Kernel.php file:

<?php
// ...    
class Kernel extends BaseKernel {
    // ...
    public function getCacheDir()
    {
        return '/tmp/symfony/'.$this->environment;
    }
    // ...
}

OpCache

Another way to reduce filesystem calls is to use the OpCache extension. To install this extension, add to the ./docker/php/Dockerfile file following lines:

RUN    docker-php-ext-install \
        opcache \
    && docker-php-ext-configure \
        opcache \
            --enable-opcache \
    && docker-php-ext-enable \
        opcache \
    && docker-pcs-php-ext-config opcache \
        # Fine tune below configuration to your needs:
        opcache.memory_consumption=256 \
        opcache.interned_strings_buffer=8 \
        opcache.max_accelerated_files=1000000 \
        opcache.fast_shutdown=1 \
        opcache.enable_cli=1 \
        opcache.enable=1 \
        # If your app makes a lot of ajax request, it is good idea to set revalidate_freq to 2 or 3 seconds
        opcache.revalidate_freq=0

If you already built container, you need to rebuild it using ./console compose build php command and run it again.

Usage

  • ./console start [SERVICES...] - starts all or selected Docker containers
  • ./console stop [SERVICES...] - stops all or selected Docker containers
  • ./console compose [ARGS...] - wrapper for docker-compose commands
  • ./console install - installs application
  • ./console create-project PACKAGE_NAME [VERSION] Creates project using composer command
  • ./console shell [--user USER] [--shell SHELL] SERVICE - opens container's shell
  • ./console clean - removes all images, containers and volumes associated with your project

docker-symfony's People

Contributors

mdobak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.