Hi I am looking at above example and trying to run docker swarm stack but getting below error. not sure what I am missing here.
docker-compose.yml
services:
nginx:
image: nginx
hostname: '{{.Node.Hostname}}'
version: '3.3'
docker stack deploy test -c docker-compose.yml
but getting below output/error : Error response from daemon: rpc
error: code = InvalidArgument desc = expanding hostname failed:
template: expansion:1:7: executing "expansion" at <.Node.Hostname>:
can't evaluate field Hostname in type struct { ID string }
Here is my docker-info output:
docker info Containers:
12 Running: 0 Paused: 0 Stopped:
12 Images: 41
Server Version: 18.03.1-ce
Storage Driver: devicemapper
Pool Name: docker-253:1-2490377-pool Pool
Blocksize: 65.54kB Base
Device Size: 10.74GB Backing Filesystem:
Thanks in advance.
I tried your setup with both version: '3.3' and version: '3.4' of compose.
According to https://docs.docker.com/engine/reference/commandline/service_create/#create-services-using-templates hostname is one of the fields you can use template strings on so this should work fine.
After creating the stack I verified the hostname with
$ docker inspect test_nginx | grep name
"com.docker.stack.namespace": "test"
"com.docker.stack.namespace": "test"
"Hostname": "{{.Node.Hostname}}",
So I think either this has been fixed in a more recent version of docker or something is odd with your host setup.
Related
I have a docker container inside which Prometheus metrics is running on port 127.0.0.1:9615
I want to access those metrics from my host machine so I did the port binding 0.0.0.0:9615->9615. But still not able to curl that url localhost:9615/metrics gives me a response
curl: (56) Recv failure: Connection reset by peer
My docker-compose file looks like that
version: '2'
services:
polkadot:
container_name: polkadot
image: parity/polkadot
ports:
- 30333:30333 # p2p port
- 9933:9933 # rpc port
- 9944:9944 # ws port
- 9615:9615
command: [
"--name", "PolkaDocker",
"--ws-external",
"--rpc-external",
"--rpc-cors", "all"
]
What mistake am I doing?
After pulling down your docker-compose.yaml it seems like you were just missing one additional CLI flag --prometheus-external.
Updated docker-compose.yaml:
version: '2'
services:
polkadot:
container_name: polkadot
image: parity/polkadot
ports:
- 30333:30333 # p2p port
- 9933:9933 # rpc port
- 9944:9944 # ws port
- 9615:9615
command: [
"--name", "PolkaDocker",
"--ws-external",
"--rpc-external",
"--rpc-cors", "all",
"--prometheus-external" # NEW FLAG HERE
]
Now if you hit localhost:9615/metrics you should see data:
# HELP polkadot_block_height Block height info of the chain
# TYPE polkadot_block_height gauge
polkadot_block_height{status="best"} 0
polkadot_block_height{status="finalized"} 0
# HELP polkadot_block_verification_and_import_time Time taken to verify and import blocks
# TYPE polkadot_block_verification_and_import_time histogram
polkadot_block_verification_and_import_time_bucket{le="0.005"} 1076
...
Based on the CLI polkadot --help the flag is described like so:
$ polkadot --help
polkadot 0.9.8-3a10ee63c-x86_64-linux-gnu
Parity Technologies <admin#parity.io>
Polkadot Relay-chain Client Node
USAGE:
polkadot [FLAGS] [OPTIONS]
polkadot <SUBCOMMAND>
FLAGS:
...
--prometheus-external
Listen to all Prometheus data source interfaces.
Default is local.
I'm trying to setup a swarm using docker but I'm having issues with communicating between containers.
I have cluster with 5 nodes. 1 manager and 4 workers.
3 apps: redis, splash, myapp
myapp has to be on the 4 workers
redis, splash just on the manager
myapp has to be able to communicate with redis and splash
I tried using the container name but its not working. It resolves the container name to different IPs.
ping splash # return a different ip than the container actually has
I am deploying running the swarm using docker stack
docker stack deploy -c docker-stack.yml myapp
Linking container between them also doesn't work.
Any ideas ? Am I missing something ?
root#swarm-manager:~# docker version
Client:
Version: 17.09.0-ce
API version: 1.32
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:42:18 2017
OS/Arch: linux/amd64
Server:
Version: 17.09.0-ce
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:40:56 2017
OS/Arch: linux/amd64
Experimental: false
docker-stack.yml contains:
version: "3"
services:
splash:
container_name: splash
image: scrapinghub/splash
ports:
- 8050:8050
- 5023:5023
deploy:
mode: global
placement:
constraints:
- node.role == manager
redis:
container_name: redis
image: redis
ports:
- 6379:6379
deploy:
mode: global
placement:
constraints:
- node.role == manager
myapp:
container_name: myapp
image: myapp_image:latest
environment:
REDIS_ENDPOINT: redis:6379
SPLASH_ENDPOINT: splash:8050
deploy:
mode: global
placement:
constraints:
- node.role == worker
entrypoint:
- ping google.com
---- EDIT ----
I tried with curl also. Didn't work.
docker stack deploy -c docker-stack.yml myapp
Creating network myapp_default
Creating service myapp_splash
Creating service myapp_redis
Creating service myapp_myapp
curl http://myapp_splash:8050
curl: (7) Failed to connect to myapp_splash port 8050: No route to host
curl http://splash:8050
curl: (7) Failed to connect to splash port 8050: No route to host
What worked is getting the actual container name of splash, which is some random generated string.
curl http://myapp_splash.d7bn0dpei9ijpba4q41vpl4zz.tuk1cimht99at9g0au8vj9lkz:8050
But this doesn't really help me.
Ping is not the proper tool to try and connect services. For some reason it doesn't work with docker networks. Try curl http://serviceName instead.
Other than that: Containers can't be named when using stack deploy, instead your service name is used (which coincidentally is the same) to access another service.
I manage to get it working using curl http://tasks.splash:8050 or http://tasks.myapp_splash:8050.
I don't know whats is causing this issue though. Feel free to comment with an answer.
It seems that containers in stack named tasks.<service name> so the command ping tasks.myservice works for me!
Itersting point to note that names like <stackname>_<service name> will also resolve and ping'able but IP address is incorrect. This is frustarating.
(For exmple if you do docker stack deploy -c my.yml AA you'll get name like AA_myservice which will resolve to incorrect addreses)
To add to above answer. From network point of view curl and ping do the same things. Both will try to resolve name passed to them and then curl will try to connect using specified protocol (http is the example above) and ping will send ICMP echo requests.
I have been playing around with docker-in-docker (dind) setups and am running into a weird problem.
If I run a docker container separately inside dind and expose a port then I could connect to the port without any problems. For example, using the docker swarm visualizer inside dind:
/home/dockremap # docker run -d -p 8080:8080 dockersamples/visualizer:stable
/home/dockremap # wget localhost:8080
Connecting to localhost:8080 (127.0.0.1:8080)
index.html 100% |*********************** ....
However, if I run the same inside a swarm by deploying from a compose file it doesn't work.
Here is what my compose file looks like:
version: "3"
services:
visualizer:
image: dockersamples/visualizer:stable
ports:
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]
networks:
- webnet
networks:
webnet:
and the commands I run:
/home/dockremap # docker swarm init
/home/dockremap # docker stack deploy -c compose.yaml test
now when I do wget I get connection refused error:
/home/dockremap # wget localhost:8080
Connecting to localhost:8080 (127.0.0.1:8080)
wget: can't connect to remote host (127.0.0.1): Connection refused
Should doing this sort of thing in dind be able to work by default, or is there something I need to configure? I am using docker 17.03.1-ce on Windows and here is what I get when I run docker info in dind:
Containers: 2
Running: 1
Paused: 0
Stopped: 1
Images: 1
Server Version: 17.05.0-ce
Storage Driver: vfs
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: active
NodeID: wz2r6iuyqztg3ivyk9fwsn976
Is Manager: true
ClusterID: mshadtrs0b1oayva2vrquf67d
Managers: 1
Nodes: 1
Orchestration:
Task History Retention Limit: 5
Raft:
Snapshot Interval: 10000
Number of Old Snapshots to Retain: 0
Heartbeat Tick: 1
Election Tick: 3
Dispatcher:
Heartbeat Period: 5 seconds
CA Configuration:
Expiry Duration: 3 months
Node Address: 172.17.0.2
Manager Addresses:
172.17.0.2:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9048e5e50717ea4497b757314bad98ea3763c145
runc version: 9c2d8d184e5da67c95d601382adf14862e4f2228
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.4.59-boot2docker
Operating System: Alpine Linux v3.5 (containerized)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 987.1MiB
Name: 7e480e7313ae
ID: EL7P:NI2I:TOR4:I7IW:DPAB:WKYU:6A6J:NCC7:3K3E:6YVH:PYVB:2L2W
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
I've installed docker-engine and docker-compose. I have only one installation of both on my system.
$ docker --version
Docker version 1.11.1, build 5604cbe
$ docker-compose --version
docker-compose version 1.7.1, build 0a9ab35
However, when I trying to execute docker-compose build, i've got this error:
ERROR: The Docker Engine version is less than the minimum required by Compose. Your current project requires a Docker Engine of version 1.10.0 or greater.
My docker-compose.yml is pretty simple:
version: '2'
services:
db:
image: postgres:9.4.1
ports:
- "5432:5432"
web:
build: .
command: bin/rails s -e development
ports:
- "3000:3000"
links:
- db
volumes:
- .:/myproject
I've have no clues on what is going on.
UPD: My system is Fedora 23.
Output of docker info
$ docker info
Containers: 9
Running: 0
Paused: 0
Stopped: 9
Images: 83
Server Version: 1.11.1
Storage Driver: devicemapper
Pool Name: docker-8:6-1188585-pool
Pool Blocksize: 65.54 kB
Base Device Size: 10.74 GB
Backing Filesystem: ext4
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 5.935 GB
Data Space Total: 107.4 GB
Data Space Available: 13.71 GB
Metadata Space Used: 6.803 MB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.141 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
WARNING: Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.109 (2015-09-22)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: null host bridge
Kernel Version: 4.4.9-300.fc23.x86_64
Operating System: Fedora 23 (Workstation Edition)
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 5.7 GiB
Name: localhost.localdomain
ID: 22QE:VZIY:26E3:WMVR:FH3Q:VYTS:FPJX:LFJ3:DHPK:EAZZ:ZDHP:56Q3
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): false
Registry: https://index.docker.io/v1/
I don't know, WTF is going on, but now it works.
I didn't do ANYTHING >_<
#VonC, #JHarris, sorry guys for wasting your time. If I'll figure out the problem, I will update my answer.
However, now I can't catch this error again.
I have deployed two docker containers which hosts two REST services deployed in Jetty.
Container 1 hosts service 1 and it Listens to 7070
Container 2 hosts service 2 and it Listens to 9090
Endpoints:-
service1:
/ping
/service1/{param}
service2:
/ping
/service2/callService1
curl -X GET http://localhost:7070/ping [Works]
curl -X GET http://localhost:7070/service1/hello [Works]
curl -X GET http://localhost:9090/ping [Works]
I have configured the containers in such a way that:
http://localhost:9090/serivce2/callService1
calls
http://localhost:7070/service1/hello
This throws a connection refused exception. Here's the configuration I have.
docker-compose.yml
------------------
service1:
build: microservice/
ports:
- "7070:7070"
expose:
- "7070"
service2:
build: microservice_link/
ports:
- "9090:9090"
expose:
- "9090"
links:
- service1
service1 Dockerfile
-------------------
FROM localhost:5000/java:7
COPY ./target/service1.jar /opt
WORKDIR /opt
ENTRYPOINT ["java", "-jar", "service1.jar","7070"]
CMD [""]
service2 Dockerfile
-------------------
FROM localhost:5000/java:7
COPY ./target/service2.jar /opt
WORKDIR /opt
ENTRYPOINT ["java", "-jar", "service2.jar","9090"]
CMD [""]
docker info
-----------
root#LT-NB-108U:~# docker info
Containers: 3
Running: 2
Paused: 0
Stopped: 1
Images: 12
Server Version: 1.10.1
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 28
Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Plugins:
Volume: local
Network: null host bridge
Kernel Version: 3.13.0-48-generic
Operating System: Ubuntu precise (12.04.5 LTS)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.47 GiB
Name: LT-NB-108U
ID: BS52:XURM:3SD7:TC3R:7YVA:ZBZK:CCL2:7AVC:RNZV:RBGW:2X2T:7C46
WARNING: No swap limit support
root#LT-NB-108U:~#
Question:-
I am trying to access the endpoint deployed in Container 1 from Container 2. However, I get a connection refused exception.
I tried exposing port 7070 in container 2. That didn't work.
curl http://service1:7070/
use - host1_name:inner_port_of_host1
That host is called "service1" in container2. Use that as the host name and the port is the inner port listener in service1's container.
If you have an express server on service1, listen on port 7070.