services section configures containers that should be started in detached mode at the begining of your pipeline. A common use case for services would be when your unit tests require a running redis server, for example:
kind: pipeline name: default services: - name: cache image: redis
Service container are reachable at a hostname identical to the container name. In our previous example, the redis container name is “cache”, and can be accessed from the pipeine at
kind: pipeline name: default steps: - name: ping image: redis commands: - redis-cli -h cache ping services: - name: cache image: redis
It is important to note the service container exit code is ignored, and a non-zero exit code does not fail the overall pipeline. Drone expects service containers to exit with a non-zero exit code, since they often need to be killed after the pipeline completes.
Services can also be defined directly in the pipeline, as detached pipeline steps. This can be useful when you need direct control over when the service is started, relative to other steps in your pipeline.
kind: pipeline name: default steps: - name: redis image: redis detach: true - name: ping image: redis commands: - redis-cli -h cache ping
This section defines a subset of yaml configuration paramters. Please see our configuration reference for a full list.
Override the default image
CMD. The command provides default executable arguments to the entrypoint.
services: - name: database image: mysql entrypoint: [ mysqld ] command: [ "--character-set-server=utf8mb4" ]
Override the default image
ENTRYPOINT. The entrypoint of an image is specifies what executable to run when the container starts.
services: - name: database image: mysql entrypoint: [ mysqld ]
Set container environment variables. You can use either an array or a dictionary. Any boolean values; true, false, yes no, need to be enclosed in quotes to ensure they are not converted to True or False by the YML parser.
services: - name: database image: postgres environment: POSTGRES_USER: postgres POSTGRES_DB: test
Specify the image to start the container from. Drone supports any valid image from any compatible Docker registry, including private registries.
image: golang image: golang:1.7 image: library/golang:1.7 image: index.docker.io/library/golang image: index.docker.io/library/golang:1.7
If the image does not exist, Drone instructs Docker to pull it. If the image is private you will need to configure registry credentials.
Gives extended privileges to this container. Docker will enable access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host.
services: - name: docker image: docker:dind privileged: true
Instruct Docker to check for a newer version of the image in the remote container registry. If a newer version is available it is automatically downloaded.
services: - name: cache image: redis:3 pull: always
Mount host paths or named volumes.
services: - name: database image: mysql volumes: - name: data path: /var/lib/mysql volumes: - name: data host: path: /var/lib/mysql
Note that named volumes are supported. If you would like to configure a named volume please consult our detailed volume documentation.
Override the default working directory.
services: - name: server image: nginx working_dir: /www
This section highlights some common problems that users encounter when configuring services. If you continue to experience issues please also check the faq. You might also want to compare your yaml to our example service configurations.
It is import to remember that you cannot use the
127.0.0.1 address to connect to services from your pipeline. Service containers are assigned their own IP address and hostname. The hostname is based on the service container name.
kind: pipeline steps: - name: ping image: redis commands: - - redis-cli -h 127.0.0.1 ping + - redis-cli -h cache ping services: - name: cache image: redis
It is important to remember that when a container is started, the software running inside the container (e.g. mysql) takes time to initialize and to start accepting connections.
Be sure to give the service adequate time to initialize before attempting to connect. A naive solution is to use the sleep command.
kind: pipeline steps: - name: ping image: redis commands: - sleep 30 - redis-cli -h cache ping services: - name: cache image: redis