Custom Services¶
Overview¶
If you need a specific service that is not included in stakkr by default, you can add
a yml file into services/
directory.
Write a Service¶
A stakkr
service respects the docker-compose
standard, plus a few customizations.
Some rules:
- The
yaml
file must be named with the same name than the service - That name will help to define the name of the service in
conf/compose.ini
- You are free to add everything you want to
conf/compose.ini
- A configuration parameter such as
php.ram
generates an environment variable that looks likeDOCKER_PHP_RAM
.
Example¶
Let’s make an nginx service. The file will be located into services/
as
nginx.yml
.
version: '2.2'
services:
nginx:
image: nginx:${DOCKER_NGINX_VERSION}
mem_limit: ${DOCKER_NGINX_RAM}
container_name: ${COMPOSE_PROJECT_NAME}_nginx
hostname: ${COMPOSE_PROJECT_NAME}_nginx
networks: [stakkr]
ports:
- "8080:80"
Now in conf/compose.ini
:
services=nginx
nginx.version=1.13-alpine
nginx.ram=256M
Restart:
$ stakkr restart --recreate
$ stakkr status
To run a command, use the standard exec
wrapper:
$ stakkr exec nginx cat /etc/nginx/nginx.conf
Build your service instead of using an existing image¶
When you need to build your own image and use it in stakkr, you just need to add a Dockerfile
,
like below, then run stakkr-compose build
each time you need to build it. Once built, a simple
stakkr start
is enough to start it.
services/memcached.yml
file :
version: '2.2'
services:
memcached:
build: ${COMPOSE_BASE_DIR}/services/memcached
mem_limit: 1024M
container_name: ${COMPOSE_PROJECT_NAME}_memcached
hostname: ${COMPOSE_PROJECT_NAME}_memcached
networks: [stakkr]
services/memcached/Dockerfile
file :
FROM memcached:1.5-alpine
# RUN ... your own logic
- In
conf/compose.ini
file, add :
services=....,memcached