Skip to content

invalid line return character in docker-entrypoint.sh prevents from using a data volume #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Cathbar2 opened this issue Jun 15, 2015 · 3 comments

Comments

@Cathbar2
Copy link

Linked to #5 and #6, it would appear that the docker-entrypoint.sh contains an invalid line return, which comments out the "chown" command, and fails the startup.

Test case to reproduce the problem :

  • Host on a Centos 7 machine, with standard docker installation
  • Install docker :
yum install docker
service docker start
docker pull docker.io/elasticsearch
  • create local folder for data and config :
mkdir -p /opt/elasticsearch/data
mkdir -p /opt/elasticsearch/config
docker run --name es -v /opt/elasticsearch/data:/usr/share/elasticsearch/data -v /opt/elasticsearch/config:/usr/share/elasticsearch/config elasticsearch

Note that you will get :

chown: changing ownership of ‘/usr/share/elasticsearch/data’: Permission denied

If you inspect the docker-entrypoint.sh, you will see that the "chown" command is commented out like so :

docker exec -ti es cat /docker-entrypoint.sh

You will get this extract as part of the file :

# Drop root privileges if we are running elasticsearch
if [ "$1" = 'elasticsearch' ]; then
        # Change the ownership of /usr/share/elasticsearch/data to elasticsearch        chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data
        exec gosu elasticsearch "$@"
fi

Note that the chown is commented out. If you uncomment it on a new line, everything works fine.

Please confirm whether this is a bug.

@Cathbar2
Copy link
Author

@bcopy follow-up

@tianon
Copy link
Member

tianon commented Jun 15, 2015

This seems OK in master:

# Drop root privileges if we are running elasticsearch
if [ "$1" = 'elasticsearch' ]; then
# Change the ownership of /usr/share/elasticsearch/data to elasticsearch
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data
exec gosu elasticsearch "$@"
fi

I've even done a hexdump to be sure:

$ hexdump -C docker-entrypoint.sh
...
000000b0  68 0a 69 66 20 5b 20 22  24 31 22 20 3d 20 27 65  |h.if [ "$1" = 'e|
000000c0  6c 61 73 74 69 63 73 65  61 72 63 68 27 20 5d 3b  |lasticsearch' ];|
000000d0  20 74 68 65 6e 0a 09 23  20 43 68 61 6e 67 65 20  | then..# Change |
000000e0  74 68 65 20 6f 77 6e 65  72 73 68 69 70 20 6f 66  |the ownership of|
000000f0  20 2f 75 73 72 2f 73 68  61 72 65 2f 65 6c 61 73  | /usr/share/elas|
00000100  74 69 63 73 65 61 72 63  68 2f 64 61 74 61 20 74  |ticsearch/data t|
00000110  6f 20 65 6c 61 73 74 69  63 73 65 61 72 63 68 0a  |o elasticsearch.|
00000120  09 63 68 6f 77 6e 20 2d  52 20 65 6c 61 73 74 69  |.chown -R elasti|
00000130  63 73 65 61 72 63 68 3a  65 6c 61 73 74 69 63 73  |csearch:elastics|
00000140  65 61 72 63 68 20 2f 75  73 72 2f 73 68 61 72 65  |earch /usr/share|
00000150  2f 65 6c 61 73 74 69 63  73 65 61 72 63 68 2f 64  |/elasticsearch/d|
00000160  61 74 61 0a 09 65 78 65  63 20 67 6f 73 75 20 65  |ata..exec gosu e|
...

(ie, no 0d/\r, only 0a/\n followed by 09/\t)

Also seems to be doing the right thing in the latest image pulled from the Hub:

$ docker pull elasticsearch
latest: Pulling from elasticsearch

25963d635584: Pulling fs layer 
19cf57dd894c: Pull complete 
e51ff1b5ec40: Pull complete 
587230b660b9: Pull complete 
167b602a607c: Pull complete 
0f8f6d06d6e2: Pull complete 
6994f8c11459: Pull complete 
fd16a44f4a07: Pull complete 
ee50ebc4c64f: Pull complete 
2354a20bfae0: Pull complete 
85528d878da2: Pull complete 
5a2a13378f3e: Pull complete 
44906177d2f4: Pull complete 
e833cbfd6f51: Pull complete 
3b5841cb4066: Pull complete 
b984041933ed: Pull complete 
06a76d26b387: Pull complete 
e54fcaa9f4d8: Pull complete 
4f01161d4b95: Pull complete 
a48fbc66fbbf: Pull complete 
66f517e19c0f: Pull complete 
38c06f9801d0: Already exists 
61b3964dfa70: Already exists 
f5224fc54ad2: Already exists 
elasticsearch:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:5f49f6aee64d80d6be2faee90800c351c5e9da2bb0c5e6cf7725e741315bc06e
Status: Downloaded newer image for elasticsearch:latest
$ docker run -it --rm elasticsearch bash
root@1d9d7fa576ac:/# bash -x /docker-entrypoint.sh elasticsearch --help
+ set -e
+ '[' e = - ']'
+ '[' elasticsearch = elasticsearch ']'
+ chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data
+ exec gosu elasticsearch elasticsearch --help
Usage: /usr/share/elasticsearch/bin/elasticsearch [-vdh] [-p pidfile] [-D prop] [-X prop]
Start elasticsearch.
    -d            daemonize (run in background)
    -p pidfile    write PID to <pidfile>
    -h
    --help        print command line options
    -v            print elasticsearch version, then exit
    -D prop       set JAVA system property
    -X prop       set non-standard JAVA system property
   --prop=val
   --prop val     set elasticsearch property (i.e. -Des.<prop>=<val>)
root@1d9d7fa576ac:/# 

@geneliu
Copy link

geneliu commented Aug 24, 2016

This is caused by selinux on the docker host. (esp. RHEL7)
set "privileged" will do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants