step1:拉取镜像
docker pull yandex/clickhouse-server:21.9.4.35
step2:启动临时文件
docker run -d --rm --name=temp yandex/clickhouse-server:21.9.4.35
step3:宿主机创建目录,用于存放配置文件、数据、日志
sudo mkdir -p /usr/local/clickhouse/conf /usr/local/clickhouse/data /usr/local/clickhouse/log
step4:将容器内配置文件拷贝到宿主机
docker cp temp:/etc/clickhouse-server/users.xml /usr/local/clickhouse/conf/users.xml
docker cp temp:/etc/clickhouse-server/config.xml /usr/local/clickhouse/conf/config.xml
step5:修改连接用户名、密码(users.xml)
PASSWORD=$(base64 < /dev/urandom | head -c8); echo "123456"; echo -n "123456" | sha256sum | tr -d '-'
其中123456是密码
返回结果
123456 #密码明文
2c297a5ee6d922c0472dee50d3067ea1ce99dd54e765247e287f9ca262525a63 #密文
step6:修改 /usr/local/clickhouse/conf/users.xml配置文件
<users>
<root> <password_sha256_hex>2c297a5ee6d922c0472dee50d3067ea1ce99dd54e765247e287f9ca262525a63</password_sha256_hex>
<networks>
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</root>
</users>
step7:删除临时容器
step8:运行
docker run -d --name clickhouse-server \
-p 8123:8123 \
-p 9009:9009 \
-p 9090:9000 \
--ulimit nofile=262144:262144 \
--volume=/usr/local/clickhouse/data:/var/lib/clickhouse \
--volume=/usr/local/clickhouse/log:/var/log/clickhouse-server \
--volume=/usr/local/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml \
--volume=/usr/local/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml \ yandex/clickhouse-server