0

Background

Say I have a docker-composer setup with a maven container, and a mysql container.

I can make the Maven container depends_on: mysql, but it doesn't wait until it's "ready". It just waits until it's running. But I have some init scripts in the MySQL container that needs to run before it's truly ready.

What I'd like to be able to do is make the Maven container wait by repeatedly trying to establish a connection to the database.

The problem with this is that the Maven container has neither iputils, nor apt-get.

Current solution

Maven allows you to hook into the lifecycle stages of the Java application, so you can do programmatic checks from the Java code. This is the current working solution. However, I'd prefer to be able to do this before the application starts, in a more CLI way.

Question

Can containers that aren't alpine or ubuntu or whatever, still get commands like ping and nc even though they don't have apt-get?

Alternatively, are there any other clever solutions to get the desired outcome?

Stoff
  • 517
  • 6
  • 22
Alec
  • 1,986
  • 4
  • 23
  • 47
  • There's quite a bit of discussion on this topic in [Docker Compose wait for container X before starting Y](https://stackoverflow.com/questions/31746182/docker-compose-wait-for-container-x-before-starting-y); do the approaches there help? Most Docker images are based on some underlying Linux distribution, most frequently Debian, so `apt-get install` is usually an option. Sending ICMP packets doesn't really prove anything (in Docker it usually tells you the container exists but not more) and I wouldn't consider ping(1) a useful tool here. – David Maze Apr 08 '22 at 13:32
  • @DavidMaze - Yes and no. That's where I got the ideas to use `depends_on` and `nc`, but as I mentioned, they don't really work in my case (as far as I know). – Alec Apr 08 '22 at 14:00

0 Answers0