ETCD搭建-docker-compose

2023-01-05  本文已影响0人  heichong

编写docker-compose.yml

cat > docker-compose.yml <<EOF
version: '3'

services:
  etcd:
    image: 'bitnami/etcd:3.5.6'
    container_name: etcd
    environment:
      - ALLOW_NONE_AUTHENTICATION=yes
      - ETCD_ADVERTISE_CLIENT_URLS=http://10.3.23.191:9904
    ports:
      - 9904:2379
      - 9905:2380
    volumes:
      - ./data:/bitnami/etcd

EOF
docker-compose up -d 

./data目录在容器启动时会被自动创建,此时如果向etcd中存储数据,会直接报错如下:

[root@KSSYSDEV etcd]# docker exec -it etcd etcdctl put name zhangsan
{"level":"warn","ts":"2023-01-05T01:13:13.199Z","logger":"etcd-client","caller":"v3@v3.5.6/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0xc00019e000/127.0.0.1:2379","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = latest balancer error: last connection error: connection error: desc = \"transport: Error while dialing dial tcp 127.0.0.1:2379: connect: connection refused\""}
Error: context deadline exceeded

原因是因为默认情况下etcd对./data没有权限,所以需要我们先手动授权

chmod 777  data

再重启etcd

docker-compose down
docker-compose up -d 

测试

[root@KSSYSDEV etcd]# docker exec -it etcd etcdctl put name zhangsan
OK
[root@KSSYSDEV etcd]# docker exec -it etcd etcdctl get name zhangsan
name
zhangsan
上一篇下一篇

猜你喜欢

热点阅读