restapidockerdocker-api

How to remove files inside a container using the Docker API


Please advise, how to remove files inside a container using the Docker API? I have tried to do it this way, but it doesn't work

curl --location --request POST 'http://192.168.1.55:5555/containers/{id}/exec' \
--header 'Content-Type: application/json' \
--data-raw '{
    "Cmd": [
        "/bin/sh",
        "-c",
        "'rm -rf /files/*'"
    ]
}'

Solution

  • According to the Docker API doc "To exec a command in a container, you first need to create an exec instance, then start it. These two API endpoints are wrapped up in a single command-line command, docker exec." In this way, after getting the response you must run new POST request /exec/{id}/start