|
| 1 | +# Experimental: Networking and Services |
| 2 | + |
| 3 | +In this feature: |
| 4 | + |
| 5 | +- `network` and `service` become a first class objects in the Docker UI |
| 6 | +- You can create networks and attach containers to them |
| 7 | +- We introduce the concept of `services` |
| 8 | + - This is an entry-point in to a given network that is also published via Service Discovery |
| 9 | + |
| 10 | +This is an experimental feature. For information on installing and using experimental features, see [the experimental feature overview](experimental.md). |
| 11 | + |
| 12 | +## Using Networks |
| 13 | + |
| 14 | + Usage: docker network [OPTIONS] COMMAND [OPTIONS] [arg...] |
| 15 | + |
| 16 | + Commands: |
| 17 | + create Create a network |
| 18 | + rm Remove a network |
| 19 | + ls List all networks |
| 20 | + info Display information of a network |
| 21 | + |
| 22 | + Run 'docker network COMMAND --help' for more information on a command. |
| 23 | + |
| 24 | + --help=false Print usage |
| 25 | + |
| 26 | +The `docker network` command is used to manage Networks. |
| 27 | + |
| 28 | +To create a network, `docker network create foo`. You can also specify a driver |
| 29 | +if you have loaded a networking plugin e.g `docker network create -d <plugin_name> foo` |
| 30 | + |
| 31 | + $ docker network create foo |
| 32 | + aae601f43744bc1f57c515a16c8c7c4989a2cad577978a32e6910b799a6bccf6 |
| 33 | + $ docker network create -d overlay bar |
| 34 | + d9989793e2f5fe400a58ef77f706d03f668219688ee989ea68ea78b990fa2406 |
| 35 | + |
| 36 | +`docker network ls` is used to display the currently configured networks |
| 37 | + |
| 38 | + $ docker network ls |
| 39 | + NETWORK ID NAME TYPE |
| 40 | + d367e613ff7f none null |
| 41 | + bd61375b6993 host host |
| 42 | + cc455abccfeb bridge bridge |
| 43 | + aae601f43744 foo bridge |
| 44 | + d9989793e2f5 bar overlay |
| 45 | + |
| 46 | +To get detailed information on a network, you can use the `docker network info` |
| 47 | +command. |
| 48 | + |
| 49 | + $ docker network info foo |
| 50 | + Network Id: aae601f43744bc1f57c515a16c8c7c4989a2cad577978a32e6910b799a6bccf6 |
| 51 | + Name: foo |
| 52 | + Type: null |
| 53 | + |
| 54 | +If you no longer have need of a network, you can delete it with `docker network rm` |
| 55 | + |
| 56 | + $ docker network rm bar |
| 57 | + bar |
| 58 | + $ docker network ls |
| 59 | + NETWORK ID NAME TYPE |
| 60 | + aae601f43744 foo bridge |
| 61 | + d367e613ff7f none null |
| 62 | + bd61375b6993 host host |
| 63 | + cc455abccfeb bridge bridge |
| 64 | + |
| 65 | +## Using Services |
| 66 | + |
| 67 | + Usage: docker service [OPTIONS] COMMAND [OPTIONS] [arg...] |
| 68 | + |
| 69 | + Commands: |
| 70 | + publish Publish a service |
| 71 | + unpublish Remove a service |
| 72 | + attach Attach a backend (container) to the service |
| 73 | + detach Detach the backend from the service |
| 74 | + ls Lists all services |
| 75 | + info Display information about a service |
| 76 | + |
| 77 | + Run 'docker service COMMAND --help' for more information on a command. |
| 78 | + |
| 79 | + --help=false Print usage |
| 80 | + |
| 81 | +Assuming we want to publish a service from container `a0ebc12d3e48` on network `foo` as `my-service` we would use the following command: |
| 82 | + |
| 83 | + $ docker service publish my-service.foo |
| 84 | + ec56fd74717d00f968c26675c9a77707e49ae64b8e54832ebf78888eb116e428 |
| 85 | + $ docker service attach a0ebc12d3e48 my-service.foo |
| 86 | + |
| 87 | +This would make the container `a0ebc12d3e48` accessible as `my-service` on network `foo`. Any other container in network `foo` can use DNS to resolve the address of `my-service` |
| 88 | + |
| 89 | +This can also be acheived by using the `--publish-service` flag for `docker run`: |
| 90 | + |
| 91 | + docker run -itd --publish-service db.foo postgres |
| 92 | + |
| 93 | +`db.foo` in this instance means "place the container on network `foo`, and allow other hosts on `foo` to discover it under the name `db`" |
| 94 | + |
| 95 | +We can see the current services using the `docker service ls` command |
| 96 | + |
| 97 | + $ docker service ls |
| 98 | + SERVICE ID NAME NETWORK PROVIDER |
| 99 | + ec56fd74717d my-service foo a0ebc12d3e48 |
| 100 | + |
| 101 | +To remove the a service: |
| 102 | + |
| 103 | + $ docker service detach a0ebc12d3e48 my-service.foo |
| 104 | + $ docker service unpublish my-service.foo |
| 105 | + |
| 106 | +# Related GitHub PRs and issues |
| 107 | + |
| 108 | +- [#13441](https://github.com/docker/docker/pull/13441) Networking UI |
| 109 | + |
| 110 | +Send us feedback and comments on [#](https://github.com/docker/docker/issues/?), |
| 111 | +or on the usual Google Groups (docker-user, docker-dev) and IRC channels. |
| 112 | + |
0 commit comments