docker

Dan Boitnott 2023-05-16T12:35:43.324159Z

Anybody understand the Docker API enough to tell how to do the equivalent of the command below using the API?

$ printf "print('hi')" |docker run -i --rm python:latest
hi
I've been trying several approaches and I can't seem to make all of these things happen at once but they're clearly possible because the CLI's doing it. 1. The input is flushed despite not ending with a newline character. 2. EOF is sent to python it writes the result and exits

lispyclouds 2023-05-16T14:27:43.305529Z

I think this would be a combination of the create, start and attach api calls. Are you using the api directly or via a programmatic interface?

lispyclouds 2023-05-16T14:30:14.595929Z

If using contajners, after the container is created and started this could be used to send data to its stdin: https://github.com/lispyclouds/contajners/blob/main/doc/002-general-guidelines.md#attach-to-a-container-and-send-data-to-stdin

Dan Boitnott 2023-05-16T15:27:20.215209Z

I am using contajners and followed the example but I've had no luck. I'm seeing suggestions that maybe the Docker CLI just handles it specially and it's not doable with the API. To clarify, I'm wanting to use contajners to launch a container, pipe in some input, then read the output until the process exits on its own.

Dan Boitnott 2023-05-16T15:27:46.061989Z

(Exits from receiving EOF since I can't guarantee there will be an exit() at the end of the input stream)

lispyclouds 2023-05-16T15:30:39.879229Z

Do you have the code that you tried that can be shared here?

lispyclouds 2023-05-16T15:34:03.550259Z

The way I’d do it is; create, start, attach to stdin, attach to stdout, container wait til it exits.

Dan Boitnott 2023-05-16T15:37:16.792719Z

I'm able to start the process and I'm able to pipe in the input and able to confirm (using docker logs -f) that it's being received and the appropriate output logged. But I don't have a way to send EOF to the running container process so that it will finish processing input and exit.

Dan Boitnott 2023-05-16T15:38:10.872049Z

Based on the documentation and what I'm finding with Google, it seems like maybe this is a known thing you can't do with the API.

lispyclouds 2023-05-16T15:42:15.733259Z

I’ll try it out when I have access to a proper machine

Dan Boitnott 2023-05-16T15:50:48.472399Z

Thanks!