当前位置: 首页 > news >正文

记 etcd 无法在docker-compose.yml启动后无法映射数据库目录的问题

1、将etcd 单独提取 Dockerfile

#镜像
FROM bitnami/etcd:3.5.11
#名称
ENV name="etcd"
#重启
ENV restart="always"
#运行无权限
ENV ALLOW_NONE_AUTHENTICATION="yes"
#端口
EXPOSE 2379 2380
#管理员权限才能创建数据库
USER root
# 设置入口点
ENTRYPOINT ["etcd"]
#命令
CMD ["--data-dir", "/etcd-data", \
"--config-file", "/opt/bitnami/etcd/conf/etcd.yaml"]

2、同目录下写配置文件 etcd.yaml

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This is the configuration file for the etcd server.

# Human-readable name for this member.
name: 'default'

# Path to the data directory.
data-dir: '/etcd-data'

# Path to the dedicated wal directory.
wal-dir:

# Number of committed transactions to trigger a snapshot to disk.
snapshot-count: 10000

# Time (in milliseconds) of a heartbeat interval.
heartbeat-interval: 100

# Time (in milliseconds) for an election to timeout.
election-timeout: 1000

# Raise alarms when backend size exceeds the given quota. 0 means use the
# default quota.
quota-backend-bytes: 0

# List of comma separated URLs to listen on for peer traffic.
listen-peer-urls: http://0.0.0.0:2380

# List of comma separated URLs to listen on for client traffic.
listen-client-urls: http://0.0.0.0:2379

# Maximum number of snapshot files to retain (0 is unlimited).
max-snapshots: 5

# Maximum number of wal files to retain (0 is unlimited).
max-wals: 5

# Comma-separated white list of origins for CORS (cross-origin resource sharing).
cors:

# List of this member's peer URLs to advertise to the rest of the cluster.
# The URLs needed to be a comma-separated list.
initial-advertise-peer-urls: http://0.0.0.0:2380

# List of this member's client URLs to advertise to the public.
# The URLs needed to be a comma-separated list.
advertise-client-urls: http://0.0.0.0:2379

# Discovery URL used to bootstrap the cluster.
discovery:

# Valid values include 'exit', 'proxy'
discovery-fallback: 'proxy'

# HTTP proxy to use for traffic to discovery service.
discovery-proxy:

# DNS domain used to bootstrap initial cluster.
discovery-srv:

# Initial cluster configuration for bootstrapping.
initial-cluster:

# Initial cluster token for the etcd cluster during bootstrap.
initial-cluster-token: 'etcd-cluster'

# Initial cluster state ('new' or 'existing').
initial-cluster-state: 'new'

# Reject reconfiguration requests that would cause quorum loss.
strict-reconfig-check: false

# Accept etcd V2 client requests
enable-v2: true

# Enable runtime profiling data via HTTP server
enable-pprof: true

# Valid values include 'on', 'readonly', 'off'
proxy: 'off'

# Time (in milliseconds) an endpoint will be held in a failed state.
proxy-failure-wait: 5000

# Time (in milliseconds) of the endpoints refresh interval.
proxy-refresh-interval: 30000

# Time (in milliseconds) for a dial to timeout.
proxy-dial-timeout: 1000

# Time (in milliseconds) for a write to timeout.
proxy-write-timeout: 5000

# Time (in milliseconds) for a read to timeout.
proxy-read-timeout: 0

client-transport-security:
  # Path to the client server TLS cert file.
  cert-file:

  # Path to the client server TLS key file.
  key-file:

  # Enable client cert authentication.
  client-cert-auth: false

  # Path to the client server TLS trusted CA cert file.
  trusted-ca-file:

  # Client TLS using generated certificates
  auto-tls: false

peer-transport-security:
  # Path to the peer server TLS cert file.
  cert-file:

  # Path to the peer server TLS key file.
  key-file:

  # Enable peer client cert authentication.
  client-cert-auth: false

  # Path to the peer server TLS trusted CA cert file.
  trusted-ca-file:

  # Peer TLS using generated certificates.
  auto-tls: false

# Enable debug-level logging for etcd.
debug: false

logger: zap

# Specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.
log-outputs: [stderr]

# Force to create a new one member cluster.
force-new-cluster: false

auto-compaction-mode: periodic
auto-compaction-retention: "1"

3、写启动脚本startetcd.sh

#构建镜像
docker build -t etcd .

sleep 1

#目录以及授权
mkdir $(pwd)/etcd-data
touch $(pwd)/etcd.yaml
sudo chmod 777 $(pwd)/etcd.yaml

docker run -d \
  -p 2379:2379 \
  -p 2380:2380 \
  -v $(pwd)/etcd-data:/etcd-data \
  -v $(pwd)/etcd.yaml:/opt/bitnami/etcd/conf/etcd.yaml \
  --name etcd \
  etcd

sleep 3

#检查是否启动成功-输出版本号
curl "http://127.0.0.1:2379/version"

4、同级目录下启动startetcd.sh

相关文章:

  • 视觉目标检测大模型GAIA
  • HTTP:三.HTTP报文
  • Win11系统 VMware虚拟机 安装教程
  • mac|使用scrcpy实现无线Android投屏
  • android TabLayout中tabBackground和background的区别
  • SSRF打靶总结
  • JS 构造函数实现封装性
  • 从keys到SCAN:Redis批量删除的进化之路
  • BT面板docker搭建excalidraw遇到的问题
  • AI大模型从0到1记录学习 day16
  • 水利水电安全员C证怎么考,报考有什么流程
  • Franka 机器人x Dexterity Gen引领遥操作精细任务新时代
  • 从三围学校项目看:中建海龙智能建造的崛起与突破
  • 安装python -m weditor报错解决方法
  • 7. 解立方根
  • 人工智能在医疗设备中的最新应用案例与技术挑战?
  • 安卓手机怎样开启双WiFi加速
  • 在线教程丨字节开源 InfiniteYou 图像生成框架,实现高保真面部特征迁移
  • 一文全面了解超融合产品:科技融合的新力量
  • 5分钟读懂ArgoCD:在Kubernetes中实现持续部署
  • 网站建设差打不开/如何做友情链接
  • 盐城网站建设公司/竞价推广代运营服务
  • 网站关键词如何部署/网络竞价托管公司
  • 建设家具网站的目的及功能定位/百度人工投诉电话是多少
  • 学做网站要学多久/拼多多seo怎么优化
  • 建设公司网站需要多少钱/个人网站首页设计