Skip to content

Wait for container dependencies upon daemon start up#50327

Merged
robmry merged 1 commit intomoby:masterfrom
Adrien-Atmosphere:50326-wait-for-dependent-containers
Jul 17, 2025
Merged

Wait for container dependencies upon daemon start up#50327
robmry merged 1 commit intomoby:masterfrom
Adrien-Atmosphere:50326-wait-for-dependent-containers

Conversation

@Adrien-Atmosphere
Copy link
Contributor

@Adrien-Atmosphere Adrien-Atmosphere commented Jul 4, 2025

- What I did
Wait for container dependencies upon daemon start up

- How I did it

  • List all dependent containers upon registration
  • Dependent containers can be either from legacy link or container network
  • Wait on a best effort basis for the dependent containers

- How to verify it

  1. Create a docker-dind container with bind mounted /var/lib/docker :
    docker run -d --privileged --name docker -v ./docker:/var/lib/docker docker-dind:latest --debug

  2. Launch a compose application that creates 500 containers in docker-dind image to maximize the chances to encounter the issue

services:
  net:
    image: alpine
    command: sleep infinity
    restart: always

  app:
    image: alpine
    command: sleep infinity
    network_mode: "service:net"
    restart: always
    scale: 500

  1. Stop and restart the docker-dind container and check for stopped containers
CONTAINER=docker
EXEC="docker exec $CONTAINER"
while true;
do 
	echo "Stopping $CONTAINER"
	docker stop $CONTAINER
	echo "Removing $CONTAINER" 
	docker rm -v $CONTAINER
	echo "Starting $CONTAINER"
        docker run -d --privileged --name docker -v ./docker:/var/lib/docker docker-dind:latest --debug
	timeout 30 bash -c "until $EXEC docker info >/dev/null 2>&1; do sleep 1; done"
	echo "$CONTAINER started successfully"

	containers=$($EXEC docker ps -aq   --filter status=created   --filter status=exited   --filter status=dead)
        if [ -n "$containers" ]
	then 
    		echo "Inspecting stopped/exited/dead containers:"
    		for i in $containers; do
		      echo "Container ID: $i"
		      $EXEC docker inspect "$i" -f "{{ .State | json }}" | jq
	        done
		exit 
	else
		echo "No created/exited/dead containers found."
	fi
done 

- Human readable description for the release notes

- On daemon startup, restart containers that share their network stacks before containers that need those stacks.

- A picture of a cute animal (not mandatory but encouraged)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Containers with "restart: always" and shared network namespace may fail to start with "cannot join network namespace of a non running container"

7 participants