4

I'm trying to use tini in my Dockerfile but I'm getting an error.

I used the code example from the tini readme file.

# ... code which builds /app/foo

# Add Tini
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini", "--"]

# Run the program when the container starts
CMD ["/app/foo"]

I expect my program to run without having PID=1 but instead I get: standard_init_linux.go:207: exec user process caused "no such file or directory"

EDIT:

/app/foo is created in the beginning of the Dockerfile. There is no problem with /app/foo. As proof of this, if I comment out the ENTRYPOINT line (or remove all the tini related code), my /app/foo runs fine except for the fact that it has PID=1

JoelFan
  • 37,465
  • 35
  • 132
  • 205
  • 3
    Wrong architecture; the thing that gets downloaded is actually a tar file or HTML page; missing shared libraries (especially if you’re running on a `scratch` image without a libc); ... – David Maze Apr 05 '19 at 03:47
  • Where did you create /app/foo? – BMitch Apr 05 '19 at 08:36
  • @BMitch, /app/foo is created in the beginning of the Dockerfile. I edited the question to clarify. – JoelFan Apr 05 '19 at 17:30
  • 1
    @JoelFan in that case, the process that makes /app/foo isn't correct. Can't really debug a comment. – BMitch Apr 05 '19 at 17:50
  • Post results of `docker exec sh -c 'ls /app` – ps-aux Apr 05 '19 at 17:58
  • Maybe instead of *telling* us what the Dockerfile looks like, just show us the actual Dockerfile. Also, note that in lieu of using `tini` you can simply use the `--init` option to `docker run`. – larsks Apr 05 '19 at 18:01
  • @larsks, this is the *relevant* part of the Dockerfile. Apparently `--init` does not work with `docker-compose`, which is what I'm using – JoelFan Apr 05 '19 at 18:04
  • [Sure it does](https://docs.docker.com/compose/compose-file/#init) This isn't something you would pass to the `docker-compose` command line; it's an attribute on services. – larsks Apr 05 '19 at 18:08
  • I got it to work with "init: true" (and removing all the `tini` and `ENTRYPOINT` code) to a certain extent.... My process no longer has PID=0... However, signal forwarding is not working... when I hit Ctrl-C, my process does not receive the signal... I will create a new question for that – JoelFan Apr 05 '19 at 19:49

3 Answers3

7

Another cause: incorrect line ends in the file. Linux expects LFs, and if your host is Windows, the script you want to run will have CRLFs.

Monsignor
  • 2,671
  • 1
  • 36
  • 34
6

Another cause could be that a script is called for which the first line points to an unavailable shell. For example, when the first line of the script (also known as the shebang) is

#!/bin/bash

Then this requires bash on the system. Changing bash to the default sh(ell) for the system can be a solution. So, replace by

#!/bin/sh

Alternatively, on some systems bash is not in /bin, but in /usr/bin/env. So, replace by

#!/usr/bin/env bash

or

#!/usr/bin/env sh
RikH
  • 2,994
  • 1
  • 16
  • 15
4

As David mentions, you need to check what is getting downloaded. If you run this by hand in an Alpine image, you'll see the exact issue:

$ docker run -it --rm alpine /bin/sh
/ # apk add file
...
/ # apk add curl
...
/ # curl -sSL https://github.com/krallin/tini/releases/download/v0.18.0/tini >tini
/ # chmod 755 tini
/ # file tini
tini: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=38c262787814dc459678c8f24710bbde944b7e56, stripped
/ # ldd tini
        /lib64/ld-linux-x86-64.so.2 (0x7f1beab2a000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f1beab2a000)
Error relocating tini: __fprintf_chk: symbol not found
/ # ./tini
/bin/sh: ./tini: not found
/ # ls -al /lib64/ld-linux-x86-64.so.2
ls: /lib64/ld-linux-x86-64.so.2: No such file or directory

Note the dynamically linked part, and the fact that it is looking for libc. The error in an Alpine scenario is telling you that libc doesn't exist. You'd also see this with a scratch image.

You'll want to either get a version of tini that is completely statically compiled, or switch to a system with libc installed. For the former, with tini, that's as easy as downloading a different URL:

ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /tini
BMitch
  • 231,797
  • 42
  • 475
  • 450