Not so long time ago I was using virtualenv and buildout for local development. It was working quite good. I didn’t have any problems with that. The only thing that bothered me was running Nginx, PostgreSQL, MySQL, Rabbitmq, Memcache etc. in my system. I had two choices, start all the servers with system boot or run them manually when I needed that. I like to have a clean system as much as possible.
About 1,5 year ago I started using Docker. It was not easy at the beginning. I spent a lot of time configuring my project but it was worth it.
Why do I like the Docker?
The main reason is that I can isolate projects totally from the system. I can create a separate containers for every project. Every container can use different software, software versions or servers.
I will give you an example. Currently I’m working in the project where we have:
- Application with Django and AngularJS/Webpack.
- Celery + Celery Flower.
- Selenium/Behave tests as a separate project.
Without Docker it looks like:
- Run Django.
- Run Webpack with AngularJS application.
- Run Celery.
- Run Flower.
- Run MySQL.
- Run RabbitMQ.
- Run Elasticsearch.
- Run Memcache.
I know, I can write a small script to do that but I still need to install everything in my system. Let’s say that I’m using PostgreSQL and Redis for another project and the list grows.
How does it look with Docker?
To run the whole system I need to use a single command
That’s all. I’ve created a simple bash script to simplify using Docker commands. Some example commands:
./docker.sh up # run the project ./docker.sh web migrate # run Django migrations ./docker.sh pytests sqlite # run python tests using SQLite ./docker.sh rebuild # rebuild the entire project ./docker.sh rebuild db # rebuild MySQL ./docker.sh chrome local # run Behave tests on local environment ./docker.sh rebuild_dependencies # Install all dependencies
Everything can be done using single command and it’s run in the container separated from the system. Let’s say that I’ve updated ElasticSearch version. The only thing which need be done is:
./docker.sh rebuild search
I think that the big advantage is also the possibility to build the entire system using one command. Sometimes the project is quite complex. When a new person comes to the project, he can install Docker, run docker-compose up and go for coffee. When he is back the system will be ready and running. If there is some big update or I break something I can use
./docker.sh rebuild and go for coffee.
The other advantage is that I can configure containers similar to how everything works on the production. Everyone with Docker will have the same settings and the same environment so it’s even better to debug issues.
There is something more. Let’s say that I need to test something. I can create a container with Ubuntu, install whatever I want, run something, break something. When I don’t need that I can run docker
rm my-container and everything is deleted and there is no tracks of my test environment.
I never used Docker for deployment. I didn’t have a possibility to try that. I’m using Docker only for local development.
Are there any problems with Docker?
Sometimes. Every software contains bugs. Sometimes, something is not working in a Docker but it works using for example virtualenv. Then I need to find some other solution. Example, two days ago I was able to run Chrome inside a Docker, I’ve updated a Chrome today and it’s not working. I saw that other people have the same issue so currently I’ve switched to Chromium and everything works. Sometimes I need more time to configure something using Docker but that’s not a problem for me. I can configure it once and everyone in the team can use that. That’s sounds also like a profit, right?
Does everyone want to use Docker?
No. In my current project only half of the team uses Docker. The second half is using just virtualenv. Everyone should use what’s easier for them. As I said, sometimes Docker needs more time and work to do something, maybe that’s why people don’t want to use Docker. The other issue could be the IDE/code editor integration with Docker. PyCharm can integrate with Docker so for example go to definitions and autocompletion works without any problems. I don’t know how it works in other editors.
What about you? Are you using Docker for local development?