herryliq
herryliq

Reputation: 11

docker exec wrong with remote docker host in Jenkins

I use Jenkins + Pipeline + DockerPlugin to build and run docker container with remote host, when execute command with the follow:

docker.withServer("tcp://192.168.1.122:2375",'') {
    def wait_results = sh(script: "docker exec -t development-taxpayer-server-131-1 echo aaa", returnStdout: true)
    print wait_results
}

wait_results : nothing to print

the expect result is print 'aaa' in Jenkins console log.

the remote docker version is:

Client:
 Version:      1.12.5
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   7392c3b
 Built:        Fri Dec 16 02:23:59 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.5
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   7392c3b
 Built:        Fri Dec 16 02:23:59 2016
 OS/Arch:      linux/amd64

Upvotes: 1

Views: 1927

Answers (1)

VonC
VonC

Reputation: 1324073

Try instead

def wait_results = sh(script: "docker ps -a", returnStdout: true)

That way you can at least check that:

  • docker is working
  • the container development-taxpayer-server-131-1 is running

Then, considering the docker exec syntax, try -it:

def wait_results = sh(script: "docker exec -it development-taxpayer-server-131-1 echo aaa", returnStdout: true)

Note: "How to run a command on an already existing docker container?" shows the same echo done without any option:

docker exec development-taxpayer-server-131-1 echo aaa

Upvotes: 1

Related Questions