{"id":19798,"date":"2015-10-31T13:04:13","date_gmt":"2015-10-31T13:04:13","guid":{"rendered":"https:\/\/blog.jetbrains.com\/phpstorm\/?p=9326"},"modified":"2024-01-09T14:59:05","modified_gmt":"2024-01-09T13:59:05","slug":"docker-support-in-phpstorm","status":"publish","type":"phpstorm","link":"https:\/\/blog.jetbrains.com\/pt-br\/phpstorm\/2015\/10\/docker-support-in-phpstorm","title":{"rendered":"Docker Support in PhpStorm"},"content":{"rendered":"<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2015\/10\/phpstorm-large_v-trans.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignright  wp-image-9328\" alt=\"large_v-trans\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2015\/10\/phpstorm-large_v-trans.png\" width=\"210\" height=\"188\" \/><\/a><a href=\"https:\/\/www.docker.com\/\" target=\"_blank\" rel=\"noopener\">Docker<\/a>\u00a0is an open platform for building, shipping and running distributed applications. It gives programmers, development teams and operations engineers the common toolbox they need to take advantage of the distributed and networked nature of modern applications.<\/p>\n<p>With the new\u00a0<a href=\"https:\/\/plugins.jetbrains.com\/plugin\/7724\" target=\"_blank\" rel=\"noopener\">Docker integration plugin<\/a>\u00a0for PhpStorm, you can add Docker support to existing projects, view logs, manage Docker containers, and debug PHP web applications from right inside PhpStorm.<\/p>\n<p>In this blog post we overview some of the most important features and configurations; for more details please refer to the\u00a0<a href=\"https:\/\/confluence.jetbrains.com\/display\/PhpStorm\/Docker+Support+in+PhpStorm\" target=\"_blank\" rel=\"noopener\">full tutorial on Docker Support in PhpStorm<\/a>.<\/p>\n<p><!--more--><\/p>\n<h2><strong>Prerequisites<\/strong><\/h2>\n<p>First of all, you&#8217;ll need to install Docker and related tools so that you can take advantage of the Docker integration in PhpStorm. Please refer to the\u00a0<a href=\"https:\/\/docs.docker.com\/\" rel=\"nofollow noopener\" target=\"_blank\">Docker documentation<\/a>\u00a0to get more information about the installation process for various platforms or the cloud.<\/p>\n<p>You will also need to install the\u00a0<em>Docker integration<\/em>\u00a0plugin in PhpStorm (in\u00a0<em>Settings \/Preferences | Plugins<\/em>, click the\u00a0<em>Install JetBrains plugin&#8230;<\/em>).<\/p>\n<h2><strong>PhpStorm &amp; Docker Integration Configuration<\/strong><\/h2>\n<p>To start using Docker, the <em>default<\/em> Docker machine should be launched using the <em>Docker Quickstart Terminal (<\/em>Windows \/ Mac OS X,\u00a0for Linux you need to use a standard terminal executing a<em>\u00a0<em>sudo docker run hello-world\u00a0<\/em><\/em>command). At the next steps we&#8217;ll need some of the parameters of this machine environment, so we&#8217;ll need to run\u00a0<em>docker-machine env default<\/em> console command to get all the necessary parameters (Windows \/ Mac OS X, for Linux you&#8217;ll need to use a standard IP address\u00a0172.17.42.1<em>)<\/em>, such as <em>DOCKER_HOST<\/em> and <em>DOCKER_CERT_PATH<\/em>:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/confluence.jetbrains.com\/download\/attachments\/70747197\/docker_4.png?version=2&amp;modificationDate=1446162133000&amp;api=v2\" width=\"563\" \/><\/p>\n<p style=\"text-align: left;\">As soon as we have Docker running (and all the parameters fetched for future use), we can start configuring PhpStorm to work with Docker.<\/p>\n<p>Create a <em>Docker configuration<\/em> with the + button in <em>Settings \/ Preferences | Build, Execution, Deployment | Clouds<\/em>:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"aligncenter\" alt=\"\" src=\"https:\/\/confluence.jetbrains.com\/download\/attachments\/70747197\/docker_5.png?version=1&amp;modificationDate=1446160285000&amp;api=v2\" width=\"650\" \/><\/p>\n<p style=\"text-align: left;\">We&#8217;ll need to provide the configuration name (<em>Docker<\/em>), <em>API URL<\/em> (<em>https:\/\/192.168.99.100:2376<\/em>, taken from the previous step), and <em>Certificates folder<\/em> (<em>\/Users\/mikhailvink\/.docker\/machine\/machines\/default<\/em>).<\/p>\n<p>Please note that you will need to provide a socket path in the API URL field on Linux machines (<em>unix:\/\/\/var\/run\/docker.sock<\/em> by default).<\/p>\n<p>Next we need to create a new <em>Docker Deployment Run\/Debug Configuration<\/em> in the\u00a0<em>Run | Edit configurations&#8230;<\/em> menu.<\/p>\n<p>Provide all the necessary parameters on the <em>Deployment<\/em>\u00a0and <em>Container\u00a0<\/em>tabs:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"aligncenter\" alt=\"\" src=\"https:\/\/confluence.jetbrains.com\/download\/attachments\/70747197\/docker_8.png?version=1&amp;modificationDate=1446163083000&amp;api=v2\" width=\"650\" \/><\/p>\n<p>At this point we are interested in exposing port 80 of the container to be available from our local machine, so we should configure a port binding for that:<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"https:\/\/confluence.jetbrains.com\/download\/attachments\/70747197\/docker_9.png?version=1&amp;modificationDate=1446163268000&amp;api=v2\" width=\"650\" \/><\/p>\n<p>There are many ways to create\/configure Docker containers and VM images; please refer to the\u00a0<a href=\"https:\/\/docs.docker.com\/\" rel=\"nofollow noopener\" target=\"_blank\">Docker documentation on their official website<\/a>.<\/p>\n<p>For the purposes of this tutorial we&#8217;re making some configuration in the\u00a0<em>Dockerfile\u00a0<\/em>and\u00a0<em>Apache configuration file<\/em>, so do have a look at them. You can\u00a0<a href=\"https:\/\/confluence.jetbrains.com\/download\/attachments\/70747197\/docker_project.zip?version=1&amp;modificationDate=1446162676000&amp;api=v2\" target=\"_blank\" rel=\"noopener\">download the entire project used in this demo<\/a>\u00a0or separate config files (<em><a href=\"https:\/\/confluence.jetbrains.com\/download\/attachments\/70747197\/apache-config.conf?version=1&amp;modificationDate=1446162700000&amp;api=v2\" target=\"_blank\" rel=\"noopener\">apache-config.conf<\/a><\/em>,\u00a0<em><a href=\"https:\/\/confluence.jetbrains.com\/download\/attachments\/70747197\/Dockerfile?version=1&amp;modificationDate=1446162711000&amp;api=v2\" target=\"_blank\" rel=\"noopener\">Dockerfile<\/a><\/em>) which then need to be placed in the project root folder.<\/p>\n<h2><strong>Running the Docker from PhpStorm<\/strong><\/h2>\n<p>As all the tools are installed and the integration is configured, the recently created <em>Start Docker<\/em> Run\/Debug Configuration can be launched.\u00a0The\u00a0<em>Application Servers<\/em>\u00a0tool window will be opened updating you on the provisioning status and current state of all your Docker containers:<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"https:\/\/confluence.jetbrains.com\/download\/attachments\/70747197\/docker_11.png?version=1&amp;modificationDate=1446164731000&amp;api=v2\" width=\"650\" \/><\/p>\n<p>As soon as our\u00a0<em>Docker_Xdebug<\/em>\u00a0container&#8217;s status turns\u00a0<em>green,<\/em>\u00a0we can check how it works in the browser. You should be able to open it with a URL similar to\u00a0<em>http:\/\/192.168.99.100:8080\/<\/em>\u00a0(<em>http:\/\/host:port<\/em>,\u00a0<em>192.168.99.100<\/em>\u00a0is the IP address of the default Docker machine).<\/p>\n<h2><strong>Managing Docker containers and other Docker-related actions in PhpStorm<\/strong><\/h2>\n<p>From the\u00a0<em>Application Servers<\/em>\u00a0tool window, it\u2019s easy to inspect containers and view the running processes. You can also search through logs, start and stop containers, and perform basic container management like creating and deleting containers.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/confluence.jetbrains.com\/download\/attachments\/70747197\/docker_13.png?version=1&amp;modificationDate=1446165468000&amp;api=v2\" width=\"650\" data-image-src=\"\/download\/attachments\/70747197\/docker_13.png?version=1&amp;modificationDate=1446165468000&amp;api=v2\" \/><\/p>\n<h2><strong>Debugging PHP web application running in the Docker container<\/strong><\/h2>\n<p>The main challenge in getting Xdebug (or Zend Debugger) working with PhpStorm and Docker integration is the correct configuration of the Docker container.<\/p>\n<p>In our case we&#8217;re using a\u00a0<em>Dockerfile<\/em>\u00a0(we&#8217;ve already shown this config earlier and provided links to download it) to configure the container, including Xdebug-specific parameters, such as:<\/p>\n<div>\n<div>\n<div>\n<div id=\"highlighter_875716\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div title=\"Hint: double-click to select code\">\n<div><code>#Set up debugger<\/code><\/div>\n<div><code>RUN echo\u00a0<\/code><code>\"zend_extension=\/usr\/lib\/php5\/20131226\/xdebug.so\"<\/code>\u00a0<code>&gt;&gt; \/etc\/php5\/apache2\/php.ini<\/code><\/div>\n<div><code>RUN echo\u00a0<\/code><code>\"xdebug.remote_enable=1\"<\/code>\u00a0<code>&gt;&gt; \/etc\/php5\/apache2\/php.ini<\/code><\/div>\n<div><code>#Please provide your host (local machine IP) instead of\u00a0<\/code><code>192.168<\/code><code>.<\/code><code>2.117<\/code><\/div>\n<div><code>RUN echo\u00a0<\/code><code>\"xdebug.remote_host=192.168.2.117\"<\/code>\u00a0<code>&gt;&gt; \/etc\/php5\/apache2\/php.ini<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Please note that\u00a0<em>xdebug.remote_host\u00a0<\/em>value should be replaced with your local machine IP address which is visible from the Docker container\u00a0(where PhpStorm is running,\u00a0in our case <em>192.168.2.117<\/em>).<\/p>\n<p>Don&#8217;t forget to re-run\u00a0<em>Start\u00a0Docker<\/em>\u00a0Run\/Debug Configuration so that all the changes are applied.<\/p>\n<p>As soon as all the configs are in place, the debugging process can be triggered by following\u00a0<a href=\"https:\/\/confluence.jetbrains.com\/display\/PhpStorm\/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm\" target=\"_blank\" rel=\"noopener\">this tutorial<\/a> starting with <strong>step 2<\/strong>\u00a0(start\u00a0<em>Listening for PHP Debug Connections,\u00a0<\/em>set a breakpoint in the source code, and start a debugging session in the browser, reload the current page, debug)\u00a0to get the debugger up and running in a few moments:<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"https:\/\/confluence.jetbrains.com\/download\/attachments\/70747197\/docker_15.png?version=1&amp;modificationDate=1446166325000&amp;api=v2\" width=\"650\" \/><\/p>\n<p>Please have a look at the\u00a0<a href=\"https:\/\/confluence.jetbrains.com\/display\/PhpStorm\/Docker+Support+in+PhpStorm\" target=\"_blank\" rel=\"noopener\">full tutorial on Docker Support in PhpStorm<\/a>\u00a0for more information.<\/p>\n<p>Please share your feedback on Docker support in PhpStorm in the\u00a0<a href=\"http:\/\/devnet.jetbrains.net\/community\/wi?view=discussions\" target=\"_blank\" rel=\"noopener\">forum<\/a>, comments to this blog post,\u00a0or our <a href=\"http:\/\/youtrack.jetbrains.com\/issues\/WI\" target=\"_blank\" rel=\"noopener\">issue tracker<\/a>. Thanks!<\/p>\n<p><em>Develop with pleasure!<\/em><br \/>\n<em>JetBrains PhpStorm Team<\/em><\/p>\n","protected":false},"author":91,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","categories":[826,808,907,2347],"tags":[2480,632,263,726,2477,792,1053],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/19798"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/types\/phpstorm"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/users\/91"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/comments?post=19798"}],"version-history":[{"count":1,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/19798\/revisions"}],"predecessor-version":[{"id":432097,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/19798\/revisions\/432097"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media?parent=19798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/categories?post=19798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/tags?post=19798"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/cross-post-tag?post=19798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}