DOCKER · Cleanup · 5 min

Remove the container, keep the image

Clean up one named practice resource without pruning unrelated work.

Not completed

Your task

Stop and remove the opsrung-cleanup container created during setup. Keep the opsrung-cleanup:practice image.

What you’re aiming for

  • The opsrung-cleanup container no longer exists.
  • The opsrung-cleanup:practice image still exists.

1. Prepare your practice folder

Use a running Docker engine in Linux container mode. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.

Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.

NEW PRACTICE FOLDER
mkdir opsrung-docker-remove-container && cd opsrung-docker-remove-container

Run these setup commands in that folder:

SETUP — RUN ONCE
cat > Dockerfile <<'DOCKERFILE'
FROM alpine:3.22
USER 65534:65534
CMD ["sleep","3600"]
DOCKERFILE
docker build -t opsrung-cleanup:practice .
docker run -d --name opsrung-cleanup --network none opsrung-cleanup:practice

Docker may download the official Alpine image and, for the web task, its HTTP package. If an example container name already exists, use a different name consistently. If port 8088 is occupied, choose another free local port.

2. Try the task

Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.

Hint 1

Run the setup commands above to create the disposable container for this task.

Hint 2

Stopping and removing are separate operations when --rm was not used.

Hint 3

Name the specific container in docker stop and docker rm. No prune command is needed.

3. Review your result

Use these commands to look at your result and compare it with the goals. The website does not run or verify them.

REVIEW IN YOUR TERMINAL
docker ps -a --filter name=opsrung-cleanup
docker image inspect opsrung-cleanup:practice

What you should see

  • docker ps -a shows no row for the exact opsrung-cleanup container.
  • docker image inspect opsrung-cleanup:practice still displays the image details.

If your result differs: Stopping a container leaves it listed until it is removed. Remove only the named practice container and keep its image; no prune command is needed.

Compare with one possible solution
ONE POSSIBLE SOLUTION
docker stop opsrung-cleanup
docker rm opsrung-cleanup

Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.

Clean up this exercise

Only remove the example resources you created. Volume cleanup deletes that exercise’s saved sample data. Keep anything you need.

OPTIONAL CLEANUP
docker image rm opsrung-cleanup:practice

Finished this exercise?

You decide when you’re done. Your choice is saved in this browser, and you can change it later.