1

I'm trying to start a container in TravisCI and then just making some docker exec to it. But it's failing everytime with 255 error code.

What I don't understand is that the process works fine locally.
I then updated my travisCI script to something very simple with standard container (ubuntu). The same is happening.

I just pull an image, run it with a no end while, and try to execute some exec to it. I use a file container_id to store the container id (that part works).

Here is my code :

$ docker pull ubuntu:latest
latest: Pulling from ubuntu
age you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Status: Downloaded newer image for ubuntu:latest

$ docker run -d ubuntu:latest sh -c "while true; do sleep 5; done" > container_id
The command "docker run -d ubuntu:latest sh -c "while true; do sleep 5; done" > container_id" exited with 0.

$ docker logs `cat container_id`
The command "docker logs `cat container_id`" exited with 0.

$ docker exec `cat container_id` sh -c "mkdir /repository"
The command "docker exec `cat container_id` sh -c "mkdir /repository"" exited with 255.

$ docker logs `cat container_id`
The command "docker logs `cat container_id`" exited with 0.

$ docker exec `cat container_id` sh -c "cd /repository ; git clone https://github.com/tdeheurles/homecores"
The command "docker exec `cat container_id` sh -c "cd /repository ; git clone https://github.com/tdeheurles/homecores"" exited with 255.

$ docker logs `cat container_id`
The command "docker logs `cat container_id`" exited with 0.

$ docker exec `cat container_id` sh -c "cd /repository/homecores ; ./test/test.sh"
The command "docker exec `cat container_id` sh -c "cd /repository/homecores ; ./test/test.sh"" exited with 255.

$ docker logs `cat container_id`
The command "docker logs `cat container_id`" exited with 0.
Done. Your build exited with 1.
Thibault Deheurles
  • 1,211
  • 13
  • 21
  • I have an alias for entering the last container started `alias exec_last='docker exec -it $(docker ps -lq) $(docker inspect -f {{'.Path'}} $(docker ps -lq))'` anyway instead of your `cat container_id` you could use `$(docker ps -lq)` – user2915097 Aug 26 '15 at 07:11
  • lots of code for a variable no ? Maybe : container_id=$(docker run -d ubuntu ...) then `docker exec $container_id ...` I just used to get the container_id back from anywhere (ssh) with the filesystem save ^^ Thanks – Thibault Deheurles Aug 26 '15 at 13:14

2 Answers2

2

Had the same problem trying to docker exec anything in Travis. I noticed this error message in /var/log/upstart/docker.log:

ERRO[0054] Error starting exec command in container 85f99b93c5307fe8ec45ea4e743147869cc25a3e5dfb91b623dd6b3eede1da3b: Cannot run exec command 85f99b93c5307fe8ec45ea4e743147869cc25a3e5dfb91b623dd6b3eede1da3b in container 8f40f7b49658cc9661446f61492d36f02e371bd4a22ef2f892f258bb856ea7e6: [8] System error: permission denied

After some digging, I'm able to work around it by running docker containers in privileged mode (docker run --privileged). Hope it helps.

Hao Xia
  • 21
  • 3
1

255 means an error has occurred.
On something as simple as a mkdir /repository, it probably means the user id within the docker exec sh session was not root, and had no right to crate a folder in /.

Check that by adding an intermediate:

docker exec `cat container_id` sh -c "id -a"

The docker exec man page mentions a -u, --user= option, so you can try:

docker exec -u root `cat container_id` sh -c "mkdir /repository"

From the discussion below, it seems the error might be related to the lack of lxc driver.

What can help (at least on circleci: see their doc on docker exec) is

sudo lxc-attach -n "$(docker inspect --format '{{.Id}}' hctest)" -- bash -c ls
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi, tnaks but still the same issue. This two commands exit with 255 ... The build logs are [here](https://travis-ci.org/tdeheurles/homecores). – Thibault Deheurles Aug 26 '15 at 13:11
  • @ThibaultDeheurles OK. Let's start by resolving the `docker exec` issue. Let's try to have one `docker exec` (*any* `docker exec`) command working. What is the ENTRYPOINT of your image? Would a ```docker exec `cat container_id` ls``` work? – VonC Aug 26 '15 at 13:14
  • No, it doesn't work. Maybe it comes from my config : https://github.com/tdeheurles/homecores/blob/master/.travis.yml – Thibault Deheurles Aug 26 '15 at 13:32
  • @ThibaultDeheurles check first what a `docker ps -a` returns after the `docker run`, just to be sure. Also, an `echo $container_id` would be good, to be sure the id has been correctly captured. – VonC Aug 26 '15 at 13:40
  • Already done. Added for the next build : https://travis-ci.org/tdeheurles/homecores/builds/77326871 – Thibault Deheurles Aug 26 '15 at 13:47
  • @ThibaultDeheurles just to test, would a `$(cat container_id)` works better than ```.`cat container_id`.```? – VonC Aug 26 '15 at 13:49
  • Same result. My feeling is about the result of docker exec (maybe the commands inside are good but outside not). I'm on windows for now (installing docker in docker to test) – Thibault Deheurles Aug 26 '15 at 13:57
  • @ThibaultDeheurles wait... are we using docker 1.8.1 with Travis-CI? Or still an old docker 1.6 or 1.7? – VonC Aug 26 '15 at 14:00
  • I created a new build : https://travis-ci.org/tdeheurles/homecores/builds/77345202 It create a nginx container with a site. `curl localhost:8000` result first in `first version`, I then exec into to change the result, another try should result in `exec change me` ... It works locally but on TravisCI it just result in nothing ... – Thibault Deheurles Aug 26 '15 at 15:31
  • Have you ever had a successfull `docker exec` on TravisCI ? – Thibault Deheurles Aug 26 '15 at 15:35
  • @ThibaultDeheurles I haven't use with docker yet. All I know is that 1.7.0 is "ancient", and (https://github.com/docker/docker/blob/v1.8.1/CHANGELOG.md#171-2015-07-14) 1.7.1 fixes the default user spawning exec process with `docker exec`. So even with -u, you might not be able to do what you want with `docker exec` in such an old docker distribution. – VonC Aug 26 '15 at 17:15
  • @ThibaultDeheurles What docker version do you have locally? (where it works) – VonC Aug 26 '15 at 17:15
  • 1.7 ;-) You're hard with 1.7 is `old` ^^ The release was in the end of june. I did use exec from 1.4 to 1.8 without any error, so that's why I'm a little lost for that arror ... Anyway, you maybe are right, this issue is maybe the one corrected by 1.8. I search on google but can't find anyone having this kind of problem. Do you know if travis have an official issue report ? – Thibault Deheurles Aug 26 '15 at 17:34
  • I didn't see the `"` around "ancient" :p – Thibault Deheurles Aug 26 '15 at 17:35
  • @ThibaultDeheurles I was ironic in my qualification of the version of docker. It is just that I consider it very much as a moving target, not yet fully mature. The blog post http://blog.travis-ci.com/2015-08-19-using-docker-on-travis-ci/ mentions "The default Docker version installed is currently 1.7.0. We'll keep it up-to-date as we roll out new build environments, but you're also free to install different versions of Docker as part your builds, the APT repository is added by default.": maybe it is possible to install an 1.8.1 for a build? – VonC Aug 26 '15 at 17:39
  • I actually looking for CircleCI solution. Will report when I finish a try. Cool for installing another version of docker, I will look at that. Thanks for your help ^^ – Thibault Deheurles Aug 26 '15 at 18:13
  • Here is the try with docker 1.8.1 : https://travis-ci.org/tdeheurles/homecores/builds/77376091 ... – Thibault Deheurles Aug 26 '15 at 18:51
  • @ThibaultDeheurles just incase, would a `docker exec ${container_id} ls` work better? – VonC Aug 26 '15 at 19:01
  • (travis build is running). I tried with CircleCI and there is an error too (https://circleci.com/gh/tdeheurles/homecores/6 ... don't know if it's public). Here is the error : `FATA[0000] Error response from daemon: Unsupported: Exec is not supported by the lxc driver docker exec $container_id sh -c "mkdir /repository" returned exit code 1` Maybe here is a start point ^^ – Thibault Deheurles Aug 26 '15 at 19:25
  • @ThibaultDeheurles as in https://github.com/dcm-oss/blockade#requirements, maybe a `DOCKER_OPTS="-e lxc"` could help here? – VonC Aug 26 '15 at 19:29
  • the workaround from CircleCI did it !! Still not working on TravisCI ... Will try your last option. It seems that docker need to be <= 1.6.2 ... trying ... – Thibault Deheurles Aug 26 '15 at 19:48
  • @ThibaultDeheurles OK! I have edited the answer accordingly in the meantime. – VonC Aug 26 '15 at 19:50
  • still not working with travis. Anyway, seeing it run in CircleCI is so good :D Thank you very much for the time you pass on that problem @VonC !! – Thibault Deheurles Aug 26 '15 at 19:53
  • @ThibaultDeheurles no problem: I am doing docker with my b2d project (https://github.com/VonC/b2d), so I was keeping an eye on your question. – VonC Aug 26 '15 at 19:54
  • Not the DOCKER_OPTS but the `sudo lxc-attach -n "$(docker inspect --format '{{.Id}}' hctest)" -- bash -c ls` from the first post you find – Thibault Deheurles Aug 26 '15 at 19:54
  • @ThibaultDeheurles OK: I have edited again the answer. – VonC Aug 26 '15 at 19:56