{"id":2277,"date":"2017-04-27T19:55:53","date_gmt":"2017-04-27T19:55:53","guid":{"rendered":"https:\/\/intelligentbee.com\/blog\/?p=2277"},"modified":"2024-11-28T14:00:03","modified_gmt":"2024-11-28T14:00:03","slug":"setup-docker-machine-symfony-development","status":"publish","type":"post","link":"https:\/\/intelligentbee.com\/blog\/setup-docker-machine-symfony-development\/","title":{"rendered":"Setup Docker Machine for Symfony Development"},"content":{"rendered":"<p>If you need a development environment for Symfony, hosted by <a href=\"https:\/\/www.docker.com\/\" target=\"_blank\" rel=\"noopener\">Docker<\/a>, you can use the\u00a0fazy\/apache-symfony docker image to start with, then extend it to your need.<\/p>\n<h2>Setup Docker Machine for Symfony Development<\/h2>\n<p>In your Symfony project&#8217;s folder add the <code>Dockerfile<\/code> and <code>docker-compose.yml<\/code> files.<\/p>\n<p>In the first one, we added <code>mysql<\/code> and <code>composer<\/code>, then we used the <code>docker-compose.yml<\/code> file to mount a local volume to the docker container with file sync.<\/p>\n<p>This way you can code on your machine and test in the docker environment.<\/p>\n<p>The <code>Dockerfile<\/code>:<\/p>\n<pre class=\"nums:false lang:ini decode:true \">FROM fazy\/apache-symfony\r\nADD . \/app\r\n\r\nRUN    apt-get update \\\r\n    &amp;&amp; apt-get -yq install \\\r\n        mysql-server \\\r\n        php5-mysql \\\r\n    &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*\r\n\r\nRUN curl -s https:\/\/getcomposer.org\/installer | php\r\nRUN mv composer.phar \/usr\/local\/bin\/composer\r\nENV COMPOSER_ALLOW_SUPERUSER 1\r\nRUN service mysql start<\/pre>\n<p>The <code>docker-compose.yml<\/code> file:<\/p>\n<pre class=\"nums:false lang:ini decode:true\">version: \"2\"\r\nservices:\r\n    site:\r\n        build: .\r\n        ports:\r\n            - \"8080:80\"\r\n        expose:\r\n            - \"80\"\r\n        volumes:\r\n          - .:\/app<\/pre>\n<p>To\u00a0build the Docker container use:<\/p>\n<p><span class=\"lang:sh decode:true crayon-inline\">docker-compose up &#8211;build<\/span><\/p>\n<p>To start it when it&#8217;s down just remove the &#8211;build parameter:<\/p>\n<p><span class=\"lang:sh decode:true crayon-inline\">docker-compose up<\/span><\/p>\n<p>Once is running, you can view it&#8217;s ID by running:<\/p>\n<p><span class=\"lang:sh decode:true crayon-inline\">docker ps<\/span><\/p>\n<p>Now grab the first 3 characters from the id and use them in the next command to be able to log in the running container:<\/p>\n<p><span class=\"lang:sh decode:true crayon-inline \">docker exec -t -i ID bash<\/span><\/p>\n<p>Finally, to access the Symfony project in your browser, go to http:\/\/localhost:8080\/app_dev.php and have fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need a development environment for Symfony, hosted by Docker, you can use the\u00a0fazy\/apache-symfony docker image to start with, [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,75,82],"tags":[],"yst_prominent_words":[308,564,593,899,977,1007,1011,1013,1063,1149,1327,1328],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/2277"}],"collection":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/comments?post=2277"}],"version-history":[{"count":4,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/2277\/revisions"}],"predecessor-version":[{"id":133334,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/2277\/revisions\/133334"}],"wp:attachment":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/media?parent=2277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/categories?post=2277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/tags?post=2277"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=2277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}