4

I'm trying to run docker container as part of a build on linux TeamCity build agent. However, if I run docker container with -i -t options, there is no output in the Build Log from executed command.

Command Line build step:

sudo docker run -i -t --name="echo_test" ubuntu echo "test"

Build Log missing output from echo command:

Step 1/2: Command Line (1s)
   [Step 1/2] Starting: /home/ec2-user/BuildAgent/temp/agentTmp/custom_script6340936320796175009
   [Step 1/2] in directory: /home/ec2-user/BuildAgent/work/831248796cfa0a04
   [Step 1/2] Process exited with code 0

Docker container logs do have the output from echo command:

[ec2-user@ip-10-28-218-103 ~]$ docker logs echo_test
test

Could someone explain why this is happening or provide some way to diagnose the issue?

If I change run docker options to either: just -i, just -t, or remove them both it works.

It's worth mentioning that at first I was getting sudo: sorry, you must have a tty to run sudo error when trying to execute sudo commands in Command Line build step in TeamCity. I commented out Default requiretty in /etc/sudoers to solve this.


I got echo to output text to Build Log by adding -a stdout -a stderr options.

Command Line build step:

sudo docker run -i -t -a stdout -a stderr --name="echo_test" ubuntu echo "test"

So the question is now why they were not required when executing command on local machine.

Domas
  • 496
  • 1
  • 6
  • 16

1 Answers1

0

I think the key information here is the error you were receiving while using sudo.

sudo: sorry, you must have a tty to run sudo

When you have a tty the stdin and stdout handles, for devices and drivers, are connected for you. But since the build does not have a tty, they are not connected for you. By attaching stdin and stdout in the run command, you connected them yourself.

When you ran the docker command locally, you ran it with a tty and the handles were connected for you by default.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Fred
  • 152
  • 5