This blog post shows how to setup a fully dockerized development suite with PhpStorm, GIT and Postman. But what is development without debugging? If all apps are dockerized you will need a workaround to be able to debug the application e.g. with PhpStorm and Xdebug. This is also considered. If you not familiar with Dockerized desktop apps, check out the Dockerized introduction. You should create your own Docker images, but for testing my Docker images should work too. The bash scripts refer to a folder data/x11docker in your home directory where x11docker stores the container config. Please create it before.
Setup GIT
To work properly with Dockerized GIT you need three things. A Docker container with GIT, the mounted source of course and your SSH credentials.
Docker Image
Let's start with the GIT Docker image. The minimal packages are git and openssh.
Start script
One cool thing of x11docker is, that it does all the heavy lifting. Don't worry about file permissions, how to share the ssh socket or to mount directories. All my sources are stored under data/sources. This makes it easy to mount the root source directory. I set the working directory to the current directory where the git command is executed. With this is feels like native GIT usage.
Create the following script named git and put it to a directory which is in your PATH variable e.g. ~/bin and make it executable.
#!/usr/bin/env bash
x11docker -q -t --sharessh --sharedir $HOME/data/sources --homedir=$HOME/data/x11docker/git --workdir $(pwd) -- sandrokeil/archlinux:git $@
Now you can use GIT as always and it works seamlessly. Ok, there are some small caveats. The start time is compared to native GIT long and you don't have bash completion. But I use PhpStorm mostly for VCS stuff.
If some SSH keys are not found, you can mount the ssh folder with --sharedir $HOME/.ssh:ro
.
Setup PhpStorm
To work efficiently with Dockerized PhpStorm you will need a Docker container with PhpStorm and the same packages like in the GIT dockerfile.
Docker Image
PhpStorm can be downloaded and extracted to /opt. I use this method in my PhpStorm Docker image. You will need the packages git, openssh, vim, gnome-keyring and libsecret to work properly. PhpStorm stores connection credentials in the Linux keyring.
Start script
The PhpStorm script has some more options like git, because we need a clipboard for copy & paste and hostdbus for credentials. I use also hostdisplay but you can also try xpra. To debug applications with PhpStorm you must add PhpStorm to the network of the application which should be debugged. I use a trick in the PhpStorm startup script to add the phpstorm container to every default network.
#!/usr/bin/env bash
# add all networks which ends with "_default" to the PhpStorm Docker container
docker network ls | grep "_default" | awk '{print $2}' | while read line
do
$(sleep 5 && docker network connect $line phpstorm) &
done
x11docker --hostdbus --name phpstorm -q --sharessh --sharedir $HOME/data/sources --homedir=$HOME/data/x11docker/phpstorm --hostdisplay --clipboard -- sandrokeil/archlinux:phpstorm
You have to set the xDebug XDEBUG_CONFIG option to remote_host=phpstorm
and ensure that xdebug.remote_connect_back is disabled. Read more about Docker PHP debugging.
Setup Postman
Postman is a popular tool for API development. It has many features like test, debug and documentation of your APIs.
Docker Image
Simply install Postman for your distro. That's it.
Start script
To interact with other Docker containers via a local domain you have to add the add-host
option with the IP of your Docker network. In this example it's 172.17.0.1 but may be vary on your host. You can also share your Downloads folder to import / export Postman collections. Debugging your APIs with xDebug works like a charm.
#!/usr/bin/env bash
x11docker --name=postman -q --xpra --homedir=$HOME/data/x11docker/postman --clipboard -- --cpus="2" --memory="2G" --add-host=awesome.local:172.17.0.1 sandrokeil/archlinux:postman
Chromium
I use a dedicated Chromium for development with installed development plugins. Some plugins have access to all data of the webpage or can even manipulate the website data. To browse a development website which is served by a Docker container via a local domain you have to add the add-host
option with the IP of your Docker network.
Conclusion
This blog post has shown how to setup a complete development environment with Docker. It's not very complicated but you have to figure out a few things. It's almost a native feeling and has so many benefits, such as: Run different versions of same application. The best thing is, that you not bloat your host system with other software.