Having issues creating a bundle from docker compose. Can't use the top level networks parameter due to it being ignored.
If I use a service level networks parameter it says the network doesn't exist...
If I leave it out, it uses default and doesn't create and overlay network.
I can create an overlay network, and start 2 services manually, but not with docker-compose bundle.
How can I get the overlay network into the bundle file?
How can I specify how many replicas in the docker-compose yml so that, too, goes into the bundle file?
Will post my docker composer file shortly but if anyone has any tips in the meantime.. :) thanks
Apologies, I misread the issue.
docker deploy should automatically create networks which are listed in the service-level networks key - if it's complaining that the network doesn't exist, I think that's a bug. Could you paste your docker-compose.yml?
How can I specify how many replicas in the docker-compose yml so that, too, goes into the bundle file?
Neither Compose files nor application bundles allow you to specify the number of replicas. In the case of the bundle, this is definitely not going to change - bundles container only config that's portable across environments, and the number of replicas for a service is not considered portable.
Thanks @aanand
Sorry - I wrote that it in haste, so apologies if it caused confusion.
The reason it didn't create the network was because I hadn't defined the top level network as it was going to be ignored, so left it out. I didn't realise the service-level had a dependancy on it (even though it's ignored).
So, fixed that issue.
However, the services created using 'docker deploy' are not accessible, yet the services created using manual commands work fine.
docker network create --driver overlay wpnet
docker service create --env MYSQL_ROOT_PASSWORD=password --env MYSQL_DATABASE=wordpress --network wpnet --replicas 1 --name wpdb mysql:latest
docker service create --env WORDPRESS_DB_HOST=wpdb --env WORDPRESS_DB_PASSWORD=password --network wpnet -p 80:80/tcp wordpress:latest
^^ that works fine. I can navigate to localhost and be presented with WP install
Note: using WP as a simple exercise
[
{
"Name": "wpnet",
"Id": "5dopu6c4hitmpylygkvsxqxax",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.0.3.0/24",
"Gateway": "10.0.3.1"
}
]
},
"Internal": false,
"Containers": {
"58e14ac0e9fcf60af1fe4e19b44c5e504fec0a83f67886293dfd953cd1d1181b": {
"Name": "happy_boyd.1.2r0sz6mvgcsvhyjfbkah1zi4w",
"EndpointID": "a8dbb4959c319eb6e87d164fbc1dae2ee258919d138a2143ef601d6a811bd0ee",
"MacAddress": "02:42:0a:00:03:05",
"IPv4Address": "10.0.3.5/24",
"IPv6Address": ""
},
"a881b1092204676bc2b6f0c7d5999802423827274098f11448223c6579ff6355": {
"Name": "wpdb.1.2244da10s4l2ikxr2sby1p42s",
"EndpointID": "9b23bad62d88e27066ed7aca24f06bc99c16e73ca7f986a5f47138c56ff33fe0",
"MacAddress": "02:42:0a:00:03:03",
"IPv4Address": "10.0.3.3/24",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "260"
},
"Labels": {}
}
]
However, if I remove those services and that network, and use my docker_compose.yml:
version: "2"
services:
wp_db:
image: mysql
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=wordpress
networks:
- wp_net
wp_web:
image: wordpress:latest
ports:
- "80:80"
environment:
- WORDPRESS_DB_HOST=docker_wp_db
- WORDPRESS_DB_PASSWORD=password
networks:
- wp_net
networks:
wp_net:
driver: overlay
{
"services": {
"wp_db": {
"Env": [
"MYSQL_ROOT_PASSWORD=password",
"MYSQL_DATABASE=wordpress"
],
"Image": "mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539",
"Networks": [
"wp_net"
],
"Ports": [
{
"Port": 3306,
"Protocol": "tcp"
}
]
},
"wp_web": {
"Env": [
"WORDPRESS_DB_HOST=docker_wp_db",
"WORDPRESS_DB_PASSWORD=password"
],
"Image": "wordpress@sha256:42e78527eda069e20ff1759286ce809d910509380e836ea97794eb5fa6311447",
"Networks": [
"wp_net"
],
"Ports": [
{
"Port": 80,
"Protocol": "tcp"
}
]
}
},
"version": "0.1"
}
Looks good. So: docker deploy docker:
Loading bundle from docker.dsb
Creating network docker_wp_net
Creating service docker_wp_db
Creating service docker_wp_web
However, navigating to localhost results in a "can't connect to server"
ID NAME REPLICAS IMAGE COMMAND
2i5u47x0gaye docker_wp_db 1/1 mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539
e9nornasfgm4 docker_wp_web 1/1 wordpress@sha256:42e78527eda069e20ff1759286ce809d910509380e836ea97794eb5fa6311447
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
22758ac18396 wordpress@sha256:42e78527eda069e20ff1759286ce809d910509380e836ea97794eb5fa6311447 "/entrypoint.sh apach" 33 seconds ago Up 32 seconds 80/tcp docker_wp_web.1.1zivowp9qlqz32gj93v974wi6
49d27232110d mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539 "docker-entrypoint.sh" 38 seconds ago Up 37 seconds 3306/tcp docker_wp_db.1.8g38kf1ogpf6winf4phpwhz39
[
{
"Name": "docker_wp_net",
"Id": "cu9c6l1tvafg9ibwttgvbqpna",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.0.0.0/24",
"Gateway": "10.0.0.1"
}
]
},
"Internal": false,
"Containers": {
"22758ac183966028d366996a7ff11521136ad9fbbdab0b0f70848d5a186eba13": {
"Name": "docker_wp_web.1.1zivowp9qlqz32gj93v974wi6",
"EndpointID": "868c777adf2174aa80e097db23a810919a8d1426f1f8d08942ba83446a831f9a",
"MacAddress": "02:42:0a:00:00:05",
"IPv4Address": "10.0.0.5/24",
"IPv6Address": ""
},
"49d27232110d145a7d0b28a69ca79f5f21e088169b872c40b634d62befb40a46": {
"Name": "docker_wp_db.1.8g38kf1ogpf6winf4phpwhz39",
"EndpointID": "cf770f96f1f01508f4121c5ae87278d58c291523f8f5e7bcca84200ee76699b3",
"MacAddress": "02:42:0a:00:00:03",
"IPv4Address": "10.0.0.3/24",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "257"
},
"Labels": {}
}
]
The main thing I notice is that this network inspect yields a near-identical result to my first, working network inspect above, so I'm really baffled as to why this is not working as expected?
Hopefully, I've included enough info here for someone to advise that I've A) found a bug or B) doing something stupid.
Many thanks! :)
docker -v
Docker version 1.12.0-rc2, build 906eacd, experimental
docker-compose -v
docker-compose version 1.8.0-rc1, build 9bf6bc6
Just to confirm - simplified my docker-compose.yml and still having the same issue:
version: "2"
services:
db:
image: mysql
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=wordpress
web:
image: wordpress:latest
depends_on:
- db
ports:
- "80:80"
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_PASSWORD=password
docker swarm init
this works:
docker-compose up
I can access the site at http://localhost
BUT:
docker-compose bundle
WARNING: Unsupported key 'depends_on' in services.web - ignoring
Wrote bundle to docker.dsb
docker deploy -f docker.dsb docker
Loading bundle from docker.dsb
Creating network docker_default
Creating service docker_db
Creating service docker_web
... navigating to localhost gives nada.
docker service inspect docker_web
docker service inspect docker_web
[
{
"ID": "2yvggavk6jtwj5ac4ujb1jpk6",
"Version": {
"Index": 196
},
"CreatedAt": "2016-07-06T13:30:11.971242539Z",
"UpdatedAt": "2016-07-06T13:30:11.975052086Z",
"Spec": {
"Name": "docker_web",
"Labels": {
"com.docker.stack.namespace": "docker"
},
"TaskTemplate": {
"ContainerSpec": {
"Image": "wordpress@sha256:42e78527eda069e20ff1759286ce809d910509380e836ea97794eb5fa6311447",
"Env": [
"WORDPRESS_DB_HOST=db",
"WORDPRESS_DB_PASSWORD=password"
]
}
},
"Mode": {
"Replicated": {
"Replicas": 1
}
},
"Networks": [
{
"Target": "8m1q27gqg8wk6sg3n62mpljb9",
"Aliases": [
"web"
]
}
],
"EndpointSpec": {
"Mode": "vip",
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 80
}
]
}
},
"Endpoint": {
"Spec": {
"Mode": "vip",
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 80
}
]
},
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 80,
"PublishedPort": 30001
}
],
"VirtualIPs": [
{
"NetworkID": "8sybuzjzlymmyyhnszl2flj20",
"Addr": "10.255.0.6/16"
},
{
"NetworkID": "8m1q27gqg8wk6sg3n62mpljb9",
"Addr": "10.0.0.4/24"
}
]
}
}
]
docker network inspect docker_default
[
{
"Name": "docker_default",
"Id": "8m1q27gqg8wk6sg3n62mpljb9",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.0.0.0/24",
"Gateway": "10.0.0.1"
}
]
},
"Internal": false,
"Containers": {
"488634b89855482094aeef5a53ad3921710a9c010e547618bf066310a1ba5e4c": {
"Name": "docker_db.1.5hjtjbyxnepfjcpvbqu7ixyr8",
"EndpointID": "e7ad1e9b5b314b01d975b8c78b3025e46fd5ea38693073fc75be184047960618",
"MacAddress": "02:42:0a:00:00:03",
"IPv4Address": "10.0.0.3/24",
"IPv6Address": ""
},
"e32d692a64be381db70077f18421795440bc658b8fb20a6a33870ccce11ba855": {
"Name": "docker_web.1.b1rq412bi6x4zmu77famle9jf",
"EndpointID": "fe98d5bcc62ec91ead933ddfe0d8b65a1930cff040777b67fc922009ec08b7b8",
"MacAddress": "02:42:0a:00:00:05",
"IPv4Address": "10.0.0.5/24",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "257"
},
"Labels": {
"com.docker.stack.namespace": "docker"
}
}
]
docker -v
Docker version 1.12.0-rc3, build 91e29e8, experimental
docker-compose -v
docker-compose version 1.8.0-rc1, build 9bf6bc6
OSX: 10.11.5 (15F34)
Whilst these services are running:
44x3ozzrbs41 docker_web 1/1 wordpress@sha256:42e78527eda069e20ff1759286ce809d910509380e836ea97794eb5fa6311447
963rq1ptos3y docker_db 1/1 mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539
.. and these containers are running:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b09bdd82cbc5 wordpress@sha256:42e78527eda069e20ff1759286ce809d910509380e836ea97794eb5fa6311447 "/entrypoint.sh apach" 6 minutes ago Up 6 minutes 80/tcp docker_web.1.9wyz6gerkkijwnhod01ml9t6t
4aa0998e51b2 mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539 "docker-entrypoint.sh" 6 minutes ago Up 6 minutes 3306/tcp docker_db.1.etulhga1758iwj75q3mw8tvj8
.. I can successfully manually start a new service, on the swarm network that the docker deploy created (docker_default):
docker service create --env WORDPRESS_DB_HOST=db --env WORDPRESS_DB_PASSWORD=password --network docker_default -p 80:80/tcp --name wpweb wordpress:latest
Now I can navigate to localhost and it works. The manual service connects to the docker deploy/bundle db service just fine.
Through elimination, I can assume the docker deploy/bundle has created a fully working swarm overlay network called docker_default, and created a fully functioning 'db' service. But with a broken 'web' service, even though it reports 1/1 ....
What's wrong with the bundle 'web' service that's causing it to be unreachable via 'localhost'? Any clues? Hoping it's a bug that can be fixed! :)
This is the bundle:
{
"services": {
"db": {
"Env": [
"MYSQL_ROOT_PASSWORD=password",
"MYSQL_DATABASE=wordpress"
],
"Image": "mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539",
"Networks": [
"default"
],
"Ports": [
{
"Port": 3306,
"Protocol": "tcp"
}
]
},
"web": {
"Env": [
"WORDPRESS_DB_HOST=db",
"WORDPRESS_DB_PASSWORD=password"
],
"Image": "wordpress@sha256:42e78527eda069e20ff1759286ce809d910509380e836ea97794eb5fa6311447",
"Networks": [
"default"
],
"Ports": [
{
"Port": 80,
"Protocol": "tcp"
}
]
}
},
"version": "0.1"
}
OK, this is an important point missing from the docs: docker-compose bundle discards any directives about binding host ports (as they're considered non-portable across environments), so after deploying, you need to expose the port on the service manually:
$ docker service update -p 80:80 docker_web
You only have to do this once - subsequent invocations of docker deploy won't overwrite it.
In future, we want to read (and have Compose automatically generate) a file with environment-specific config like this, so you don't have to do this step manually.
Genius, will try this - thanks @aanand! :)
Worked great @aanand ... However, if I then go to update the stack, I get an error:
docker deploy -f docker.dsb myapp
Loading bundle from docker.dsb
Updating service myapp_db (id: en3iy3g6jqxb5wsl3qqqdc567)
Error response from daemon: rpc error: code = 2 desc = changing network in service is not supported
Not critical of course, I'm just testing the new bundle stuff.
Not at all - thanks for reporting. Does this error happen even when you run docker deploy with exactly the same bundle as before?
If so, would you mind opening an issue on docker/docker for this? You can leave out the bundle generation command.
@aanand ran into the same issue. Followed your suggestion doing docker service update. Now, how do I find where the container is running so that I can access it? I have three nodes with swarm-mode enabled.
docker service inspect shows an IP address, but that seems to be the address exposed within the overlay.
Docker service ls
Docker network inspect nrtwork_name
Does that help @ppadala?
docker service ls doesn't show where to access them
root@ubuntu:~/cxa_wordpress# docker service ls
ID NAME REPLICAS IMAGE COMMAND
2ed0djuv5lys cxawordpress_db 1/1 mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539
6u5qs2w07emd cxawordpress_wordpress 1/1 wordpress@sha256:42e78527eda069e20ff1759286ce809d910509380e836ea97794eb5fa6311447 /bin/sh -c sleep 60; /entrypoint.sh apache2-foreground
The IP addresses listed in docker network inspect cxawordpress and ingress are not accessible from the hosts, which I am guessing means they are not routable. How do I find an endpoint for the container that I can access in host IP network?
root@ubuntu:~/cxa_wordpress# docker network inspect cxawordpress_default
[
{
"Name": "cxawordpress_default",
"Id": "2alo7u8mxuk7zljnxjrok02kd",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.0.0.0/24",
"Gateway": "10.0.0.1"
}
]
},
"Internal": false,
"Containers": {},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "257"
},
"Labels": {
"com.docker.stack.namespace": "cxawordpress"
}
}
]
root@ubuntu:~/cxa_wordpress# docker network inspect ingress
[
{
"Name": "ingress",
"Id": "d7lxefqdhq2m7umxh6bwam6ym",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.255.0.0/16",
"Gateway": "10.255.0.1"
}
]
},
"Internal": false,
"Containers": {
"c3adaa36b9cd563da97e5f793da7ab766c6b1df9b47fb71d91175719eb807e2b": {
"Name": "cxawordpress_wordpress.1.ev7ulnqn8zb96brx06e9j119e",
"EndpointID": "93d8c6287b66a93ba0a48f7e5f28286a4e11c116b17afef95f792d00ff842de9",
"MacAddress": "02:42:0a:ff:00:08",
"IPv4Address": "10.255.0.8/16",
"IPv6Address": ""
},
"ingress-sbox": {
"Name": "ingress-endpoint",
"EndpointID": "f15da69b675cd11ec41e2a75f3ff00ec2634adddfa06ba10f42eb0f6e22de048",
"MacAddress": "02:42:0a:ff:00:03",
"IPv4Address": "10.255.0.3/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "256"
},
"Labels": {}
}
]
You can access them from localhost? Or the IP of the host, right?
You can access them from localhost? Or the IP of the host, right?
Which host? I have a swarm with three hosts. That's my question actually, how do I find where the containers are running and what are the endpoints?
@ppadala Docker services use a routing mesh, so once you've exposed a port with docker service update -p, you should be able to access that port on any node in the swarm.
FWIW:
127.0.0.1:80 will probably be your friend WP install whilst 127.0.0.1:3306 will be your db.. ?
Http://localhost should bring up the WP site, if you have docker running locally
@ppadala Docker services use a routing mesh, so once you've exposed a port with docker service update -p, you should be able to access that port on any node in the swarm.
That was my understanding as well. But, can't access through host IPs. Also checked that no firewall is active. What am I missing?
root@ubuntu:~# docker service ls
ID NAME REPLICAS IMAGE COMMAND
2ed0djuv5lys cxawordpress_db 1/1 mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539
6u5qs2w07emd cxawordpress_wordpress 1/1 wordpress@sha256:42e78527eda069e20ff1759286ce809d910509380e836ea97794eb5fa6311447 /bin/sh -c sleep 60; /entrypoint.sh apache2-foreground
root@ubuntu:~# docker service update -p 80:80 cxawordpress_wordpress
cxawordpress_wordpress
root@ubuntu:~# curl http://172.16.117.134
curl: (7) Failed to connect to 172.16.117.134 port 80: Connection refused
root@ubuntu:~# curl http://172.16.117.135
curl: (7) Failed to connect to 172.16.117.135 port 80: Connection refused
root@ubuntu:~# curl http://172.16.117.136
curl: (7) Failed to connect to 172.16.117.136 port 80: Connection refused
root@ubuntu:~# ufw status
Status: inactive
Quick addition: I am using VMware Fusion VMs running on my Mac. Let me know, if there is some configuration that needs to be checked.
Most helpful comment
OK, this is an important point missing from the docs:
docker-compose bundlediscards any directives about binding host ports (as they're considered non-portable across environments), so after deploying, you need to expose the port on the service manually:You only have to do this once - subsequent invocations of
docker deploywon't overwrite it.In future, we want to read (and have Compose automatically generate) a file with environment-specific config like this, so you don't have to do this step manually.