0

I'm trying to run elasticsearch in docker and my current directory is as follows :

es:.
│   createindices.sh
│   Dockerfile
│
└───analysis
        wn_s.pl

my dockerfile is as follows which works perfectly, however, this version requires me to manually run the createindices.sh file in container

FROM elasticsearch:6.5.4
WORKDIR /app
ADD . /app
ADD analysis /usr/share/elasticsearch/config/analysis
COPY createindices.sh .
EXPOSE 9200
EXPOSE 9300

I updated my dockerfile as follows with an intention to run createindices.sh after the container is up and running

FROM elasticsearch:6.5.4
WORKDIR /app
ADD . /app
ADD analysis /usr/share/elasticsearch/config/analysis
COPY createindices.sh .
EXPOSE 9200
EXPOSE 9300
ENTRYPOINT ["/bin/bash"]
CMD ["./createindices.sh"]

the image builds successfully but i get following error when running a container with image made:

$ docker logs es
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to ::1: Cannot assign requested address
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to ::1: Cannot assign requested address
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to ::1: Cannot assign requested address

I've never received this error and i couldn't find much on stackoverflow.

Irfan Harun
  • 979
  • 2
  • 16
  • 37
  • I guess `./createindices.sh` does something with elasticsearch, that since is not running is causing the issue? – Federkun Aug 09 '19 at 19:02
  • `./createindices.sh` basically contains curl PUT request that creates new indices for elasticsearch to use. it works fine when i run it manually.after the container is running. I just want to automate this step as this dockerfile will be used along with other docker files in my docker-compose.yml file in final stage – Irfan Harun Aug 09 '19 at 19:06
  • 1
    Please see [my previous answer about this](https://stackoverflow.com/a/57328930/10008173): this is impossible to do in the Dockerfile and very difficult to do from within the same container. Run the script from the host or a separate container. – David Maze Aug 09 '19 at 19:06
  • @DavidMaze, m actually running django and elasticsearch with intentions of having a docker-compose file as method of running both django and elasticsearch in their separate containers. my thought process was to make everything work in dockerfile and append the dockerfile to docker-compose for ease of usage. is there a way to run the bash file not from dockerfile but from docker-compose.yml file ?? – Irfan Harun Aug 09 '19 at 19:55
  • @DavidMaze: After a bit more of research, i've realized that i can probably use `HEALTHCHECK` to confirm if elasticsearch is up and running and then execute my bash file. Another option would be run a new container with the purpose to run the bash file to create index after a specified delay like explained in https://github.com/davidefiocco/dockerized-elasticsearch-indexer . Can you please confirm if my understanding is right ? – Irfan Harun Aug 10 '19 at 04:59
  • 1
    The overall structure of that setup seems sound (run the "indexer" from a separate container). I'd probably use something like the `wait-for-it` script or a polling loop to check if ES is up yet rather than a fixed delay. – David Maze Aug 10 '19 at 09:34

0 Answers0