Skip to content
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

Usage with Docker #57

Open
agustisanchez opened this issue Mar 5, 2018 · 10 comments

Comments

@agustisanchez
Copy link

@agustisanchez agustisanchez commented Mar 5, 2018

In order to use it with Docker and docker-compose,
place it alongside Dockerfile, build it into the image with exec permissions and reference it in docker-compose.yml.

- Dockerfile
- wait-for-it.sh
#Dockerfile
...
COPY wait-for-it.sh /wait-for-it.sh
RUN chmod +x /wait-for-it.sh
...
#docker-compose.yml
...
  my-service:
    build:
      context: "."
      container_name: my_container
      command: ["/wait-for-it.sh", "mysql:3306", "--", [entrypoint function]]
...
@douglas-gibbons

This comment has been minimized.

Copy link
Collaborator

@douglas-gibbons douglas-gibbons commented Nov 4, 2018

Thanks @agustisanchez - I like it. Depending on your setup, you might also copy wait-for-it.sh in as a mounted volume, such as this:

version: '3'

services:
  hello-world:
    image: ubuntu
    volumes:
      - ./wait-for-it.sh:/usr/local/bin/wait-for-it.sh
    command:
      - wait-for-it.sh
      - github.com:80
      - --
      - echo
      - "hello world"
@portolkyz

This comment has been minimized.

Copy link

@portolkyz portolkyz commented Jan 9, 2019

Depending on the base image used there will be no netcat available in the container. The description pure bash conflicts in this case with the fact that netcat is no shell builtin. No offense intended.

Cheers

@Tux1234

This comment has been minimized.

Copy link

@Tux1234 Tux1234 commented Feb 12, 2019

Can you tell me what my Entrypoint is?
Given are the following snippets.

#Dockerfile

FROM java:8
VOLUME /tmp
EXPOSE 8080
COPY wait-for-mysql.sh /wait-for-mysql.sh
RUN chmod +x /wait-for-mysql.sh
ADD target/App.jar App.jar.
ENTRYPOINT ["java","-jar","App.jar"]

Im not shure with my ENTRYPOINT. I do the follwoing.
#docker-compose.yml

...
  mysql-docker-container:
  ..
  .
  my-service:
    build:
      context: "."
      container_name: my_container
      command: ["./wait-for-mysql.sh", "mysql-docker-container:3306", "--", "java", "App.jar"]
....

Is the Entrypoint correct?

@Calimerico

This comment has been minimized.

Copy link

@Calimerico Calimerico commented Apr 20, 2019

I think that your command should look like this:
command: ["./wait-for-mysql.sh", "mysql-docker-container:3306", "--", "sh", "-c", "java", "App.jar"]

@alexgivi

This comment has been minimized.

Copy link

@alexgivi alexgivi commented May 20, 2019

to find out what is default entrypoint - do next steps:

  1. comment entrypoint config line in docker-compose.yml
  2. start service (docker-compose up -d)
  3. inspect service (docker inspect my_container) and find info about entrypoint. also it's possible to view entrypoint via docker ps, but string is truncated.
  4. modify your entrypoint: "wait-for-it mysql-docker-container:3306 -- default-entrypoint", replace "default-entrypoint" to your actual command
@yaoyuanyy

This comment has been minimized.

Copy link

@yaoyuanyy yaoyuanyy commented May 22, 2019

In order to use it with Docker and docker-compose,
place it alongside Dockerfile, build it into the image with exec permissions and reference it in docker-compose.yml.

- Dockerfile
- wait-for-it.sh
#Dockerfile
...
COPY wait-for-it.sh /wait-for-it.sh
RUN chmod +x /wait-for-it.sh
...
#docker-compose.yml
...
  my-service:
    build:
      context: "."
      container_name: my_container
      command: ["/wait-for-it.sh", "mysql:3306", "--", [entrypoint function]]
...

@agustisanchez what is the "entrypoint function" in docker-compose.yml

@yaoyuanyy

This comment has been minimized.

Copy link

@yaoyuanyy yaoyuanyy commented May 22, 2019

@agustisanchez if i want to run a java project, what is the "entrypoint function"

@alexgivi

This comment has been minimized.

Copy link

@alexgivi alexgivi commented May 26, 2019

https://docs.docker.com/compose/compose-file/#command
https://docs.docker.com/compose/compose-file/#entrypoint
there is some difference between command and entrypoint.
personally I prefer to use entrypoint config and don't use command.

@jakzal

This comment has been minimized.

Copy link

@jakzal jakzal commented May 31, 2019

Multistage builds can be leveraged to install wait-for-it with apt-get:

FROM debian:buster-slim as wait-for-it
RUN apt-get update && apt-get install -y "wait-for-it"

FROM debian:buster-slim
COPY --from=wait-for-it /usr/bin/wait-for-it /usr/bin/wait-for-it

If there was an official docker image for wait-for-it (i.e. wait-for-it/wait-for-it) we could potentially do:

FROM debian:buster-slim
COPY --from=wait-for-it/wait-for-it /usr/bin/wait-for-it /usr/bin/wait-for-it
@kunal-bhatia

This comment has been minimized.

Copy link

@kunal-bhatia kunal-bhatia commented Jun 12, 2019

@douglas-gibbons Is it possible to use it with google distroless java images?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.