You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Docker确保CDH容器重启或停止后不丢失工作成果?

Fixing CDH Docker Data Loss & Auto-Restart on Mac

Hey there! I totally get the frustration of losing your work after a restart—let’s get this sorted out so your CDH setup stays intact no matter what. The issue here boils down to two things: temporary container storage (by default, Docker doesn’t save data inside containers when they stop/restart) and missing auto-restart configuration (your container wasn’t set to fire up again when your Mac rebooted).

1. Persist Your CDH Data with Docker Volumes or Bind Mounts

First, we need to make sure your CDH data (configs, HDFS storage, Cloudera Manager settings, etc.) lives outside the container, so it survives stops, restarts, or even container deletion.

Docker volumes are managed by Docker itself, so they’re more reliable and avoid permission headaches on Mac. Here’s how to set it up:

  • Create a dedicated volume for CDH:
    docker volume create cdh-persistent-storage
    
  • When starting your CDH container, mount this volume to the critical directories inside the container. For example, if your CDH image stores core data in /var/lib/cloudera-scm-server and /hdfs-data, your run command would look like:
    docker run -d \
      --name cdh-container \
      -v cdh-persistent-storage:/var/lib/cloudera-scm-server \
      -v cdh-persistent-storage:/hdfs-data \
      your-cdh-image-name
    
    Note: Check your CDH image’s documentation to find exactly which directories need persistence—these are just common examples.

Option 2: Use Bind Mounts (Manual Local Directory)

If you prefer to store data in a specific folder on your Mac, use a bind mount:

  • Create a local directory to hold your CDH data:
    mkdir -p ~/Documents/cdh-data
    
  • Mount this directory when starting the container:
    docker run -d \
      --name cdh-container \
      -v ~/Documents/cdh-data:/var/lib/cloudera-scm-server \
      -v ~/Documents/cdh-data:/hdfs-data \
      your-cdh-image-name
    
    Pro tip: On Mac, if you run into permission errors, make sure the local directory has read/write access for all users (or adjust the container user’s permissions via the image settings).

2. Configure Auto-Restart for Your CDH Container

Next, we’ll make sure the container automatically starts up when your Mac (or Docker Desktop) reboots.

Set Auto-Restart When Creating a New Container

Add the --restart flag to your run command. There are two useful options:

  • --restart always: The container will restart every time Docker starts, even if you manually stopped it before rebooting.
  • --restart unless-stopped: The container will restart on Docker startup only if you didn’t manually stop it (this is safer if you sometimes need to keep the container off).

Example with both persistence and auto-restart:

docker run -d \
  --name cdh-container \
  --restart unless-stopped \
  -v cdh-persistent-storage:/var/lib/cloudera-scm-server \
  your-cdh-image-name

Update an Existing Container’s Restart Policy

If you already have a container set up and don’t want to recreate it, you can update its restart policy:

docker update --restart unless-stopped cdh-container

3. Recover Your Lost Data (If Needed)

If you want to salvage the work from your old container:

  1. Start the old container (if it’s stopped):
    docker start cdh-container-old
    
  2. Copy the critical data from the container to your local machine:
    docker cp cdh-container-old:/var/lib/cloudera-scm-server ~/cdh-recovery
    
  3. Stop and delete the old container:
    docker stop cdh-container-old && docker rm cdh-container-old
    
  4. Create a new persistent container and copy the recovered data into it:
    docker run -d \
      --name cdh-container \
      --restart unless-stopped \
      -v cdh-persistent-storage:/var/lib/cloudera-scm-server \
      your-cdh-image-name
    docker cp ~/cdh-recovery/. cdh-container:/var/lib/cloudera-scm-server
    

Final Checks

After setting this up:

  • Reboot your Mac and verify the container starts automatically (docker ps should show it running).
  • Make a small change in your CDH setup (e.g., create a test HDFS directory), stop the container, start it again, and confirm the change is still there.

内容的提问来源于stack exchange,提问作者miteshsc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:56:37