Disabling services with Docker profiles


Disabling services with Docker profiles

Docker Compose allows us to easily start multiple containers at the same time, saving us from starting them all manually. However, as your project grows, you might realize that you don’t always need all services to develop or test your application. By using profiles, you can easily customize your compose file for different environments or uses.

Show me the code

In this example, we are upgrading the docker-compose.yaml from our previous article. We will put the services geoserver-db and geoserver-db into a separate profile. The reason for that is that since we are not always working with maps, we can improve the initialization time of our containers a bit, and also save on performance if we are not running GeoServer. To accomplish that, all we need to do is add the profiles attribute in the services that we do not always want to start.

So now if I were to start my containers simply with “docker compose up -d”, it would only start Kibana, Elasticsearch, and the setup service. That’s because services without a profile are always started (or stopped). Then in case I wanted to start everything, I’d just need to specify the profile in the command, like this: “docker compose –profile maps up -d”.