You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Docker卸载Portainer镜像失败,容器自动生成求助

Hey there, let's work through this step by step since you're new to Docker—no worries, this is a common gotcha! 😊

Fixing Portainer Image Removal & Auto-Restarting Containers

The reason new containers keep popping up is likely your original Portainer container was set with an auto-restart policy (like --restart=always), so Docker automatically recreates it when you delete the old one. Here's how to fully resolve this:

Step 1: View All Containers (Even Stopped Ones)

The docker container ls command only shows running containers. To see every container tied to the Portainer image (including stopped ones), run:

docker container ls -a --filter ancestor=portainer/portainer:latest

This will list all related containers with their IDs and statuses, so you can confirm which ones are linked to the image.

Step 2: Force Stop & Delete All Portainer Containers

Since the containers auto-restart, we need to force-stop and delete them in one go to prevent immediate recreation. Run this command to target all Portainer-related containers at once:

docker rm -f $(docker ps -aq --filter ancestor=portainer/portainer:latest)
  • The -f flag forces the container to stop (if running) and delete it immediately.
  • docker ps -aq --filter ancestor=... grabs all container IDs associated with the Portainer image, so you don't have to type each ID manually.

Step 3: Delete the Portainer Image

Now that no containers are using the image, you can safely remove it:

docker rmi portainer/portainer:latest

If you still get an error, add the -f flag to force the deletion (though the previous step should have cleared up any conflicts):

docker rmi -f portainer/portainer:latest

Step 4: Reinstall Portainer Correctly (Optional)

If you want to set up Portainer again with a new password, use this standard, beginner-friendly command (it includes proper persistence and safe restart settings):

docker run -d -p 9000:9000 \
  --name portainer \
  --restart=unless-stopped \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v portainer_data:/data \
  portainer/portainer:latest

Let's break down what each part does for you:

  • -d: Runs the container in the background (so it doesn't tie up your terminal)
  • -p 9000:9000: Maps your local port 9000 to the container's port 9000 (so you can access the UI)
  • --name portainer: Gives the container a friendly name instead of a random ID, making it easier to manage
  • --restart=unless-stopped: Restarts the container automatically unless you manually stop it (safer than always if you need to take it down later)
  • -v /var/run/docker.sock:/var/run/docker.sock: Lets Portainer access your Docker daemon to manage containers
  • -v portainer_data:/data: Creates a dedicated volume to save Portainer's settings (so you won't lose your config if the container is deleted)

After running this, wait 30 seconds, then visit http://127.0.0.1:9000—you'll be able to set a new admin password without issues.

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

火山引擎 最新活动