0

I try to set up two dockers. One with service and one with a database. On my docker with service, I try to run script wait-for-it.sh from https://github.com/vishnubob/wait-for-it.

I tried to do all this stuff using a docker-compose file, but I isolate my problem to running .sh file at the start of a container.

FROM openjdk:8-jdk-alpine
RUN apk add --no-cache bash
COPY ./target/docker-demo-0.0.1-SNAPSHOT.jar  /app.jar
COPY ./src/main/resources/wait-for-it.sh  /wait-for-it.sh
ENTRYPOINT ["/wait-for-it.sh", "192.168.99.100:5432", "--", "java", "-jar", 
"/app.jar"]
EXPOSE 8080

I was using clean ash from the alpine image, Next, I was installing bash. Of course, i was changing the first line of code of script from

#!/usr/bin/env bash

into

#!/bin/sh

or

#!/bin/bash

Nothing help. I saw this topic How to run a bash script in an Alpine Docker container but it did not help either.

I always receive "no such file or directory". I was messing with

ENTRYPOINT ["/wait-for-it.sh"...

by adding "." or "./"

The entire project I am building on windows with docker tool for windows 8. Maybe there is a reason?

1
  • Can you add RUN ls -la / after COPY wait-for-it.sh. And see what happen Commented Feb 9, 2018 at 4:25

3 Answers 3

2

I had the same issue. Two days I spent figuring out why it's not working. My host machine is windows, so the wait-for-it.sh file was formatted for dos.

  1. I had to run dos2unix wait-for-it.sh command to convert the file for unix systems. (Convert files to unix systems)
  2. I added in the Dockerfile these 3 lines:

RUN apk add --no-cache bash
COPY wait-for-it.sh /wait-for-it.sh
RUN chmod +x /wait-for-it.sh

Afterwards the wait-for-it.sh ran when the container was starting.

If you are using GIT, git handles line endings depending by host machine. You have to add a file .gitattributes inside your project and add into this file this line *.sh eol=lf. So you are telling that all your .sh files to have the line endings in LF

Sign up to request clarification or add additional context in comments.

2 Comments

Great answer. I am sorry I can't upvote you. One thing. Did you install dos2unix on docker? Or you just did it manually in your environment?
I didn't install dos2unix on docker, I've did it manually on my host machine
0
COPY ./src/main/resources/wait-for-it.sh  /wait-for-it.sh

This line is the culprit. Use this if the script is in absolute directory

COPY /src/main/resources/wait-for-it.sh  /wait-for-it.sh

or use this if the script is in relative directory

COPY src/main/resources/wait-for-it.sh  /wait-for-it.sh

and then run this

RUN chmod 700 /wait-for-it.sh

2 Comments

Vamsi, thanks for answer. My COPY comand with script works fine. I see script in the same place where my jar inside docker is. So this should not be a problem.
Did you try setting the permissions like mentioned in the last step.
0
  1. In the copy statement try giving the target folder only.

    e.g. COPY ./src/main/resources/wait-for-it.sh /app

  2. Also set the working directory where the container starts

    WORKDIR /app

Also ensure that you have given execute permissions to the file like @vamsi suggested in his answer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.