Running Docker from Jenkins

Hi,

I try to run the following in a jenkins shell build step job:

script --return -qc ‘sudo docker run -it 2fca032f7fdd’ /dev/null

I use ‘script’ here otherwise I get “no tty” error.
the image was built by this dockerfile:
FROM busybox

COPY ci-job.sh ci-job.sh
ENTRYPOINT ["/bin/sh"]
CMD [“ci-job.sh”]

And ‘ci-job.sh’:

for i in 1 2 3 4 5; do
echo "sleeping for 15 sec"
sleep 15
done
exit 32

Jenkins is running the container as expected but returns immediately as opposed to wait till the container exits by itself.

I would appreciate any help, basically I want to be able to run this container from jenkins and to report the correct exit code.

Thanks
Roey

I’m not sure, what’s going on here, but I might be able to give you some pointers:

  1. Try running it without the ‘script’ part. Instead omit the -it options. You don’t need -i, since you’re not typing into the container and you don’t need -t because Jenkins will print the container output anyway…

  2. Maybe ‘sudo’ is the problem?! If Jenkins can’t run docker commands without using sudo, you’ll need to add Jenkins to the docker group. (You might need to create the group. Don’t forget to re-login/reboot after…)

@hejado Thanks for your replay, I resorted to a different flow, where I run the container with -d (and a command that keeps it running), then I’ll use ‘exec’ to run other commands.