2018-10-01 17:27:15 +00:00
|
|
|
---
|
2020-04-07 18:55:19 +00:00
|
|
|
layout: docs
|
2020-04-06 20:27:35 +00:00
|
|
|
page_title: 'Commands: Services'
|
2020-04-07 23:56:08 +00:00
|
|
|
sidebar_title: 'services'
|
2020-04-07 18:55:19 +00:00
|
|
|
sidebar_current: docs-commands-services
|
2018-10-01 17:27:15 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Consul Agent Services
|
|
|
|
|
|
|
|
Command: `consul services`
|
|
|
|
|
|
|
|
The `services` command has subcommands for interacting with Consul services
|
2020-04-09 23:46:54 +00:00
|
|
|
registered with the [local agent](/docs/agent/basics). These provide
|
2018-10-01 17:27:15 +00:00
|
|
|
useful commands such as `register` and `deregister` for easily registering
|
|
|
|
services in scripts, dev mode, etc.
|
|
|
|
To view all services in the catalog, instead of only agent-local services,
|
2020-04-09 23:46:54 +00:00
|
|
|
see the [`catalog services`](/docs/commands/catalog/services) command.
|
2018-10-01 17:27:15 +00:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
Usage: `consul services <subcommand>`
|
|
|
|
|
|
|
|
For the exact documentation for your Consul version, run `consul services -h` to
|
|
|
|
view the complete list of subcommands.
|
|
|
|
|
|
|
|
```text
|
|
|
|
Usage: consul services <subcommand> [options] [args]
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
Subcommands:
|
|
|
|
deregister Deregister services with the local agent
|
|
|
|
register Register services with the local agent
|
|
|
|
```
|
|
|
|
|
|
|
|
For more information, examples, and usage about a subcommand, click on the name
|
|
|
|
of the subcommand in the sidebar.
|
|
|
|
|
|
|
|
## Basic Examples
|
|
|
|
|
|
|
|
To create a simple service:
|
|
|
|
|
2020-04-07 23:56:08 +00:00
|
|
|
```shell
|
2018-10-01 17:27:15 +00:00
|
|
|
$ consul services register -name=web
|
|
|
|
```
|
|
|
|
|
|
|
|
To create a service from a configuration file:
|
|
|
|
|
|
|
|
```text
|
|
|
|
$ cat web.json
|
|
|
|
{
|
|
|
|
"Service": {
|
|
|
|
"Name": "web"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$ consul services register web.json
|
|
|
|
```
|
|
|
|
|
|
|
|
To deregister a service:
|
|
|
|
|
2020-04-07 23:56:08 +00:00
|
|
|
```
|
2018-10-01 17:27:15 +00:00
|
|
|
# Either style works:
|
|
|
|
$ consul services deregister web.json
|
|
|
|
|
|
|
|
$ consul services deregister -id web
|
|
|
|
```
|