<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gerard Rico Botella</title>
    <description>The latest articles on DEV Community by Gerard Rico Botella (@gricob).</description>
    <link>https://dev.to/gricob</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F684789%2F5fdcdd78-d3a3-4996-897f-4c0669450679.jpg</url>
      <title>DEV Community: Gerard Rico Botella</title>
      <link>https://dev.to/gricob</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gricob"/>
    <language>en</language>
    <item>
      <title>How to manage docker-compose Symfony project using Make</title>
      <dc:creator>Gerard Rico Botella</dc:creator>
      <pubDate>Sat, 18 Jun 2022 19:19:21 +0000</pubDate>
      <link>https://dev.to/gricob/how-to-manage-docker-compose-symfony-project-using-make-fp0</link>
      <guid>https://dev.to/gricob/how-to-manage-docker-compose-symfony-project-using-make-fp0</guid>
      <description>&lt;p&gt;In my &lt;a href="https://dev.to/gricob/how-to-setup-docker-compose-for-symfony-projects-47kn"&gt;previous post&lt;/a&gt; I explained how to setup docker-compose for a symfony project. Manage docker-compose projects can be anoying if we use docker/docker-compose commands for it. With Make, we can manage it in a simpler way.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Make?
&lt;/h2&gt;

&lt;p&gt;According to the make page from &lt;a href="https://www.gnu.org/software/make/" rel="noopener noreferrer"&gt;GNU project website&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files.&lt;/p&gt;

&lt;p&gt;Make gets its knowledge of how to build your program from a file called the makefile, which lists each of the non-source files and how to compute it from other files. When you write a program, you should write a makefile for it, so that it is possible to use Make to build and install the program.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A good place to learn how to use Makefiles is &lt;a href="https://makefiletutorial.com/#getting-started" rel="noopener noreferrer"&gt;makefiletutorial website&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How would we use Make?
&lt;/h2&gt;

&lt;p&gt;As you can see in its definition, it's main pourpose is to generate files from source code, but we will use it to simplificate execution of the commands needed to manage a docker-compose symfony project. &lt;/p&gt;

&lt;p&gt;Make's targets allows us to create aliases to other commands. For example, to run a symfony command in your container you will run something like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker exec -it bin/console your:command&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you need to run this command often, this could become anoying. With make, we can define the following target:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console/%
    docker exec -it bin/console $*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use this target you simply run &lt;/p&gt;

&lt;p&gt;&lt;code&gt;make console/your:comand&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That is pretty much simpler than docker's full command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating our Makefile
&lt;/h2&gt;

&lt;p&gt;Firs of all, we create a file name &lt;code&gt;Makefile&lt;/code&gt; in our project root directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker related targets
&lt;/h3&gt;

&lt;p&gt;The first target we are going to create is to execute docker-compose commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight make"&gt;&lt;code&gt;&lt;span class="nl"&gt;docker-compose/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nv"&gt;USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;USER&lt;span class="p"&gt;}&lt;/span&gt; docker-compose &lt;span class="nv"&gt;$*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;USER=${USER}&lt;/code&gt; is to tell docker-compose which user we want to use inside the container. This is needed to prevent permissions errors between host and container generated files. &lt;br&gt;
To make it work, we will add the following variable at the begining of our Makefile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight make"&gt;&lt;code&gt;&lt;span class="nv"&gt;USER&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;$(&lt;/span&gt;shell &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;:&lt;span class="p"&gt;$(&lt;/span&gt;shell &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, we are setting the &lt;code&gt;user:group&lt;/code&gt; of our user to the &lt;code&gt;USER&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;Finally, we need to add &lt;code&gt;user&lt;/code&gt; option to our service configuration (in docker-composer.yml) and set it to the environment variable &lt;code&gt;$USER&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;example_php:
    container_name: example_php
    user: $USER
    build:
      context: .
    working_dir: /var/www/app/
    volumes:
      - './:/var/www/app/'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Helper targets
&lt;/h4&gt;

&lt;p&gt;To keep things simple on our daily usage, we will add the following helper targets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;up: Build and start services&lt;/li&gt;
&lt;li&gt;start: Start services&lt;/li&gt;
&lt;li&gt;stop: Stop services&lt;/li&gt;
&lt;li&gt;build: Build or rebuild services&lt;/li&gt;
&lt;li&gt;exec: Execute commands inside PHP service&lt;/li&gt;
&lt;li&gt;bash: Execute bash inside our PHP service
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight make"&gt;&lt;code&gt;&lt;span class="nl"&gt;up&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make docker-compose/&lt;span class="s2"&gt;"up -d"&lt;/span&gt;

&lt;span class="nl"&gt;start&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make docker-compose/&lt;span class="s2"&gt;"start"&lt;/span&gt;

&lt;span class="nl"&gt;stop&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make docker-compose/&lt;span class="s2"&gt;"stop"&lt;/span&gt;

&lt;span class="nl"&gt;build&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make docker-compose/build

&lt;span class="nl"&gt;exec/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="p"&gt;${&lt;/span&gt;PHP_CONTAINER&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nv"&gt;$*&lt;/span&gt;

&lt;span class="nl"&gt;bash&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make &lt;span class="nb"&gt;exec&lt;/span&gt;/bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Other targets
&lt;/h3&gt;

&lt;p&gt;Given the previously defined docker targets, it's easy to add targets. For example, we can add a symfony console target to run console commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight make"&gt;&lt;code&gt;&lt;span class="nl"&gt;console/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make &lt;span class="nb"&gt;exec&lt;/span&gt;/&lt;span class="s2"&gt;"bin/console &lt;/span&gt;&lt;span class="nv"&gt;$*&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we use the &lt;code&gt;exec&lt;/code&gt; target previously defined.&lt;br&gt;
We can add all targets that we could need using this format.&lt;/p&gt;

&lt;h3&gt;
  
  
  All together
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight make"&gt;&lt;code&gt;&lt;span class="c"&gt;# ----------------------------------------------------------------------------
# Configuration
# ----------------------------------------------------------------------------
&lt;/span&gt;
&lt;span class="nv"&gt;USER&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;$(&lt;/span&gt;shell &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;:&lt;span class="p"&gt;$(&lt;/span&gt;shell &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;NGINX_CONTAINER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"example_nginx"&lt;/span&gt;
&lt;span class="nv"&gt;PHP_CONTAINER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"example_php"&lt;/span&gt;

&lt;span class="c"&gt;# ----------------------------------------------------------------------------
# Docker
# ----------------------------------------------------------------------------
&lt;/span&gt;
&lt;span class="nl"&gt;docker-compose/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nv"&gt;USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;USER&lt;span class="p"&gt;}&lt;/span&gt; docker-compose &lt;span class="nv"&gt;$*&lt;/span&gt;

&lt;span class="nl"&gt;up&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make docker-compose/&lt;span class="s2"&gt;"up -d"&lt;/span&gt;

&lt;span class="nl"&gt;build&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make docker-compose/build

&lt;span class="nl"&gt;exec/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="p"&gt;${&lt;/span&gt;PHP_CONTAINER&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nv"&gt;$*&lt;/span&gt;

&lt;span class="nl"&gt;bash&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make &lt;span class="nb"&gt;exec&lt;/span&gt;/bash

&lt;span class="c"&gt;# ----------------------------------------------------------------------------
# Composer
# ----------------------------------------------------------------------------
&lt;/span&gt;
&lt;span class="nl"&gt;composer/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make &lt;span class="nb"&gt;exec&lt;/span&gt;/&lt;span class="s2"&gt;"composer &lt;/span&gt;&lt;span class="nv"&gt;$*&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nl"&gt;composer-install&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make composer/&lt;span class="s2"&gt;"install"&lt;/span&gt;

&lt;span class="nl"&gt;composer-require/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make composer/&lt;span class="s2"&gt;"require &lt;/span&gt;&lt;span class="nv"&gt;$*&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nl"&gt;composer-require-dev/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make composer/&lt;span class="s2"&gt;"require --dev &lt;/span&gt;&lt;span class="nv"&gt;$*&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# ----------------------------------------------------------------------------
# Symfony
# ----------------------------------------------------------------------------
&lt;/span&gt;
&lt;span class="nl"&gt;console/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make &lt;span class="nb"&gt;exec&lt;/span&gt;/&lt;span class="s2"&gt;"bin/console &lt;/span&gt;&lt;span class="nv"&gt;$*&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# ----------------------------------------------------------------------------
# Tests
# ----------------------------------------------------------------------------
&lt;/span&gt;
&lt;span class="nl"&gt;phpunit/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make &lt;span class="nb"&gt;exec&lt;/span&gt;/&lt;span class="s2"&gt;"vendor/bin/phpunit -c phpunit.xml.dist &lt;/span&gt;&lt;span class="nv"&gt;$*&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nl"&gt;test&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make phpunit/&lt;span class="s2"&gt;" "&lt;/span&gt;

&lt;span class="nl"&gt;test/%&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;make phpunit/&lt;span class="s2"&gt;"--testsuite &lt;/span&gt;&lt;span class="nv"&gt;$*&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to use it
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Set up
&lt;/h3&gt;

&lt;p&gt;If you don't have built your services yet, run &lt;code&gt;make up&lt;/code&gt;.&lt;br&gt;
If services are already built, run &lt;code&gt;make up&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Dependencies
&lt;/h3&gt;

&lt;p&gt;Run &lt;code&gt;make composer-install&lt;/code&gt; to install all dependencies.&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;make composer-require/example/package&lt;/code&gt; to require packages. For example, to install ramsey/uuid, you will run &lt;code&gt;make composer-require/ramsey/uuid&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Symfony commands
&lt;/h3&gt;

&lt;p&gt;You can run any symfony command running &lt;code&gt;make console/your:command&lt;/code&gt;. For example, if you need to clear cache, you will run &lt;code&gt;make console/cache:clear&lt;/code&gt;. You can pass arguments and options wrapping command into double quotes: &lt;code&gt;make console/cache:clear -e prod&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tests
&lt;/h3&gt;

&lt;p&gt;To run all suites, run &lt;code&gt;make test&lt;/code&gt;. &lt;br&gt;
If you want to run only your unit test suite, run &lt;code&gt;make test/unit&lt;/code&gt;&lt;/p&gt;

</description>
      <category>symfony</category>
      <category>php</category>
      <category>docker</category>
      <category>make</category>
    </item>
    <item>
      <title>How to setup docker-compose for Symfony projects</title>
      <dc:creator>Gerard Rico Botella</dc:creator>
      <pubDate>Sat, 18 Jun 2022 10:54:40 +0000</pubDate>
      <link>https://dev.to/gricob/how-to-setup-docker-compose-for-symfony-projects-47kn</link>
      <guid>https://dev.to/gricob/how-to-setup-docker-compose-for-symfony-projects-47kn</guid>
      <description>&lt;h2&gt;
  
  
  [OPTIONAL] Create symfony project
&lt;/h2&gt;

&lt;p&gt;For this example, we create a simple symfony project using composer &lt;code&gt;create-project&lt;/code&gt; command using package &lt;code&gt;symfony/skeleton&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer create-project symfony/skeleton example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't have composer installed, you can find how to do it in &lt;a href="https://getcomposer.org/doc/00-intro.md" rel="noopener noreferrer"&gt;it's official website&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create PHP-FPM Dockerfile
&lt;/h2&gt;

&lt;p&gt;Create a file named &lt;code&gt;Dockerfile&lt;/code&gt; in your project root and write the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM php:8.1-fpm

COPY --from=composer /usr/bin/composer /usr/bin/composer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example we are using &lt;code&gt;php:8.1-fpm&lt;/code&gt; image from &lt;a href="https://hub.docker.com/_/php?tab=description&amp;amp;page=1" rel="noopener noreferrer"&gt;php official images&lt;/a&gt; but other FPM images are valid too if its PHP version satisfies symfony project requirements.&lt;/p&gt;

&lt;p&gt;In order to manage composer dependencies, we copy composer binary from composer official image using &lt;a href="https://docs.docker.com/develop/develop-images/multistage-build/#use-an-external-image-as-a-stage" rel="noopener noreferrer"&gt;multi-stage builds&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create nginx configuration
&lt;/h2&gt;

&lt;p&gt;Create &lt;code&gt;nginx.conf&lt;/code&gt; file in your project root and write the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;events {
    worker_connections 1024;
}

http {
    server {
        server_name  example.app;
        root /var/www/app/public;

        location / {
            try_files $uri /index.php$is_args$args;
        }

        location ~ ^/index\.php(/|$) {
            fastcgi_pass example_php:9000;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;

            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;

            internal;
        }

        location ~ \.php$ {
            return 404;
        }

        error_log /var/log/nginx/api_error.log;
        access_log /var/log/nginx/api_access.log;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important things here are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;root /var/www/app/public&lt;/code&gt; defines the directory where de index file is located.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fastcgi_pass example_php:9000&lt;/code&gt; instructs nginx to execute PHP scripts using server &lt;code&gt;example_php&lt;/code&gt; and port &lt;code&gt;9000&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Puting all together
&lt;/h2&gt;

&lt;p&gt;To comunicate nginx with php, we create &lt;code&gt;docker-compose.yaml&lt;/code&gt; file in project root with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
  example_nginx:
    container_name: example_nginx
    image: nginx:1.21.3-alpine
    restart: on-failure
    volumes:
      - './:/var/www/app:ro'
      - './nginx.conf:/etc/nginx/nginx.conf:ro'
    ports:
      - "9081:80"
    depends_on:
      - example_php

  example_php:
    container_name: example_php
    build:
      context: .
    working_dir: /var/www/app/
    volumes:
      - './:/var/www/app/'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  example_nginx
&lt;/h3&gt;

&lt;h4&gt;
  
  
  image
&lt;/h4&gt;

&lt;p&gt;Indicates docker-compose the image that should be used to create the container. You can find more official images &lt;a href="https://hub.docker.com/_/nginx" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  restart
&lt;/h4&gt;

&lt;p&gt;Indicates when should the container be restarted. You can find more info in &lt;a href="https://docs.docker.com/compose/compose-file/#restart" rel="noopener noreferrer"&gt;compose specification&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  volumes
&lt;/h4&gt;

&lt;p&gt;Makes files available for the service container. In this case, we are using two volumes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;'./:/var/www/app:ro'&lt;/code&gt; that binds project files to &lt;code&gt;/var/www/app&lt;/code&gt; directory in readonly mode&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'./nginx.conf:/etc/nginx/nginx.conf:ro'&lt;/code&gt; that binds nginx configuration file to &lt;code&gt;/etc/nginx/nginx.conf&lt;/code&gt; in readonly mode&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find more info about volumes &lt;a href="https://docs.docker.com/compose/compose-file/#volumes" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  ports
&lt;/h4&gt;

&lt;p&gt;Binds container port &lt;code&gt;80&lt;/code&gt; to localhost &lt;code&gt;9081&lt;/code&gt;. This allows us to access out symfony application using URL &lt;code&gt;http://localhost:9081&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can find more info about ports &lt;a href="https://docs.docker.com/compose/compose-file/#ports" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  depends_on
&lt;/h4&gt;

&lt;p&gt;Expresses that this service dependens on service &lt;code&gt;example_php&lt;/code&gt;. Remember that we configured nginx to use &lt;code&gt;example_php&lt;/code&gt; as &lt;code&gt;fastcgi_pass&lt;/code&gt; server.&lt;/p&gt;

&lt;p&gt;You can find more info about &lt;code&gt;depends_on&lt;/code&gt; &lt;a href="https://docs.docker.com/compose/compose-file/#depends_on" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  example_php
&lt;/h3&gt;

&lt;h4&gt;
  
  
  context
&lt;/h4&gt;

&lt;p&gt;Defines the path to the directory where the Dockerfile is located. In this case, we have both Dockerfile and docker-compose.yml in the same directory and that's why we simple use &lt;code&gt;.&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can find more info about build configuration &lt;a href="https://docs.docker.com/compose/compose-file/build/#context-required" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  working_dir
&lt;/h4&gt;

&lt;p&gt;Sets the application root directory as working directory to simplificate running application commands using &lt;code&gt;docker exec&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  volumes
&lt;/h4&gt;

&lt;p&gt;In this service, we make all application files available in read and write mode in order to allow write operations like cache generation and install dependencies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Runing the app
&lt;/h2&gt;

&lt;p&gt;To run the app, we just need to run &lt;code&gt;docker-compose up&lt;/code&gt; and access our app using the URL &lt;code&gt;http://localhost:9081&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>symfony</category>
      <category>php</category>
    </item>
  </channel>
</rss>
