The setup for Portainer is pretty similar to that of phpMyAdmin, sans the additional network setup part. This means that we can access our application at for example, immediately when we do docker-compose up -d! Setting up We will be using it to reverse proxy any requests made to a local domain to the Docker container’s port 80 (by default) using nginx, which will automatically reload once a new Docker container is started or stopped. Thankfully, nginx-proxy exists, which is an “automated nginx reverse proxy for Docker”. However, we haven’t yet solved the problem with having to manually setting ports ourselves, which turns out to be slightly more than just a minor annoyance if you have to do it every day. What we managed to do so far with Docker Compose is to containerize the three required programs for our Laravel application, and it should be running smoothly. Setting up virtual hosts with nginx-proxy This will require the developer to explicitly bind the port, or to use a managed service to do this for us. Since every developer on the project is not guaranteed to have port 3000 available, you should be putting port bindings to host strictly within the file. Version : ' 3' services : php-nginx : ports : - 3000:80 To migrate an existing project, I added a dev/ directory which may look like the following: I decided to go ahead with richarvey/nginx-php-fpm as I have always used that image for PHP development, and it exposes the application through a port. How this works is that each project expects to have some dependencies, be it WordPress which expects php and mysql, or a Jekyll project which expects ruby and jekyll.įor example, let’s talk about a Laravel project, which requires the following: php, mysql, redis. I even went so far as to do brew uninstall nginx and brew uninstall mysql on my machine, migrating the local development environment for most of my existing projects (that I still care about) to Docker. Once I properly picked up Docker in May this year, I found myself Dockerizing (almost) everything - from production deployments to development environments as well. Do give it a star if it has helped you! :) TL DR: The scripts used in this post, along with a sample project using Docker can be found on GitHub: docker-local-dev-env. This called for a rather lot of work each time I required to create a new project with both frontend and backend parts, and I wanted to see how this can be done away with. How I normally get around this would be to set up a virtual host route on my local nginx server, reverse proxy my-project.local to localhost:3000 and myproject.local/api to localhost:3001, and reference the API via instead. When you have to deal with many of such projects concurrently, it starts to get a bit of a pain to remember which ports are taken, debug stupid errors where your app can’t connect because you changed the port, and so on.Īdditionally, if you run a UI application using webpack-dev-server on say localhost:3000, and an API server on localhost:3001, the UI dev server running on localhost:3000 cannot communicate with localhost:3001 on modern browsers (such as Chrome) without running into Cross-Origin Resource Sharing (CORS) errors. I typically work on web development projects, some of which require running a local server exposed on a certain TCP port (such as localhost:3000). But as I started experimenting and dabbling into more languages and runtimes, along with various work requirements, it started to get a bit painful to maintain separate runtimes and separate versions on your computer, and have to set up the same environment if I move to another computer (which I haven’t done so recently, thankfully). Traditionally, on my Macbook, I would use Homebrew for installing a local nginx server, a shared MySQL instance containing all my projects’ databases, as well as a PHP 7.1 runtime. Or even worse, if you have to use different versions of PHP or MySQL for example, for different projects. This is especially true if you’re like me, who works on concurrent projects at the same time. Recently I’ve been using Docker for about almost everything, because it’s so neat at compartmentalising messy dependencies, build environments, and so on. Setting up all your local dev environments with Docker
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |