the input device is not a TTY
Answered
Hi,
My Teamcity Job needs to open a shell in a running docker container and run a few commands, I was originally using
docker exec -it $(containerID sh
It gave me the error "the input device is not a TTY" and I can now understand because its not actually opening a terminal to logon and the suggestion was to remove the "-t" flag
But after removal of the flag,
docker exec -i ${contaierID} sh
It doesn't exec into the container shell and quietly exits the command without an error!
Not sure how to fix this!
Please help.
Please sign in to leave a comment.
I am not sure if you can run an interactive shell in a Docker container from a non-interactive environment. Can you tell me more about your objective? Why not just run each command like 'docker exec <container ID> <command>'?
Good Morning Eric
We have a Linux box which hosts Linux based Docker containers running Golang programs with each container being a 'sandbox' environment for developers. The Teamcity job delivers a file that needs to be accessed from inside the Docker container.
Now, the Containers were initially created mapping to a volume in the host Linux box and this value is available as an Env variable in the container's Linux box.
In order for each dev to make the container look up their Git branch, the Teamcity Job creates a Git Branch specific subdirectory in the mapped volume.
The task is now to dev to change the Env variable inside the container to point to their subdirectory and restart the Golang program.
So, the script to be run INSIDE the container could be
export MYVAR='/mainDirectorypath.../GitbranchSubDirectory
kill -i << running Go program>>
./Restart a new instance of the Go program
exit
Of course, I can what the script does manually but thought I can automate it!!
All suggestions welcome, please.
Thanks for the additional details. I agree that automation is the way to go wherever it is possible, but you can still automate the whole thing even if each command is part of a script. Are you expecting the Go program to return some results during this build step and is it also required that the docker container remain running continuously?
I think it may be possible to use the Docker Wrapper for this sort of task, running the entire build step within the container. However, this would spawn a new container each time and the container would stop at the end of the build step and you mentioned you were trying to run the commands in an already running container. So it might not be a good fit for your situation.
Another, possibly overly complicated, approach would be to call a script that is in your container. The script should use environment variables that you could pass to the container from the command line runner. For example, you could have mycustomscript.sh preloaded on your container with something like:
Then the command line build step within your TeamCity build configuration would be something like:
Then you would need to add the parameters to your build configuration and set them to the required values for each build, which can be done programmatically for automation.
-Eric
That's great Eric, will give it a shot today and update.
Thanks for such a clear explanation!!