dockerode icon indicating copy to clipboard operation
dockerode copied to clipboard

Container.inspect() always returns ERR_UNESCAPED_CHARACTERS

Open AlexanderProd opened this issue 5 years ago • 6 comments

I'm trying to get the details of a container using the Container.inspect() method. The container was successfully returned using dockerode.getContainer(id) but when I call inspect() on this container I only get the following error.

TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters
    at new ClientRequest (_http_client.js:148:13)
    at Object.request (http.js:46:10)
    at h.request (/home/server/node_modules/docker-modem/lib/http.js:51:52)
    at Modem.buildRequest (/home/server/node_modules/docker-modem/lib/modem.js:214:67)
    at Modem.dial (/home/server/node_modules/docker-modem/lib/modem.js:202:8)
    at /home/server/node_modules/dockerode/lib/container.js:64:18
    at new Promise (<anonymous>)
    at Container.inspect (/home/server/node_modules/dockerode/lib/container.js:63:12)
    at /home/server/dist/docker/helpers.js:35:56
    at Generator.next (<anonymous>) {
  code: 'ERR_UNESCAPED_CHARACTERS'
}

I'm using: dockerode version 3.1.0 Node v10.16.0 Docker version 19.03.5 MacOS

AlexanderProd avatar Feb 15 '20 13:02 AlexanderProd

Just ran the tests against those versions, the only difference was that I used node v13.8.0. Everything worked fine.

Could you provide an example?

apocas avatar Feb 18 '20 10:02 apocas

I've just tried it with node v13.8.0 but it didn't work either.

This is what I'm doing. I want to get the details of a container from inside the container, to do this I've mounted /var/run/docker.sock.

const thisContainer = docker.getContainer(await getSelfCID());
return(JSON.stringify(await thisContainer.inspect()));

getSelfCID() returns the id of the docker container from inside the container.

export const getSelfCID = (): Promise<string> => {
  return new Promise((resolve, reject) => {
    exec('cut -c9- < /proc/1/cpuset', (error, stdout) => {
      if (error) {
        reject(error);
      }
      resolve(stdout);
    });
  });
};

This works and returns the valid id which I'm then using to get details of the container to using inspect. I can properly inspect it by running docker container inspect [id] on the host.

The only problem is inspect() always returns the error shown above.

AlexanderProd avatar Feb 18 '20 11:02 AlexanderProd

I've noticed this only happens when my container tries to inspect 'itself', inspect() works fine with other containers. I don't understand why this is the case though, I can inspect other containers from inside but not the own container.

Do you have an idea why this is the case?

AlexanderProd avatar Feb 19 '20 14:02 AlexanderProd

FWIW, I had the same error message (just using kill() instead of inspect()) and the problem was a bug in my code:

I accidentally called docker.getContainer(name) with a Function instead of a string for name. The getContainer() call will not fail in this scenario, and the error will be deferred to whatever function you call on the resulting container object, which also don't seem to do an argument validation.

Just leaving this here in case someone else makes the same mistake.

A small dockerode improvement could be stricter argument validation on getContainer().

alexkli avatar Apr 20 '20 18:04 alexkli

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Open a new issue if needed.

stale[bot] avatar Apr 25 '21 18:04 stale[bot]

I've noticed this only happens when my container tries to inspect 'itself', inspect() works fine with other containers. I don't understand why this is the case though, I can inspect other containers from inside but not the own container.

For anyone else having this issue, know that the container ID should be a 64 character long string. When getting the ID of the current container, either through exec('cut -c9- < /proc/1/cpuset', (error, stdout) => { ... }) or through reading /proc/1/cpuset and then applying basename to it, you have to trim the newline off the end of the string.

Unlikely that others will run across this but if you do, this will likely fix your issue.

adamkdean avatar Sep 21 '21 00:09 adamkdean

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Open a new issue if needed.

stale[bot] avatar Mar 25 '23 16:03 stale[bot]