memex-in commited on
Commit
b6cfdce
·
verified ·
1 Parent(s): 15d3c02

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +49 -12
start.sh CHANGED
@@ -1,22 +1,57 @@
1
- #!/bin/sh
 
 
2
 
3
- # Start the rootless Docker daemon in the background
4
- # The `docker:dind-rootless` image's ENTRYPOINT is already `dockerd-rootless.sh`.
5
- # We need to ensure it runs as the primary process, and then our commands follow.
6
- # The `dind-rootless` image sets up the environment variables for rootless mode.
7
- # We'll run dockerd directly and wait for it.
8
 
9
- echo "Starting dockerd-rootless.sh in the background..."
10
- dockerd-rootless.sh &
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  # Wait for the Docker daemon to be fully ready
13
- # This loop is more robust than a fixed sleep
14
  until docker info >/dev/null 2>&1; do
15
- echo 'Waiting for Docker daemon to start...'
16
  sleep 1
17
  done
18
  echo 'Docker daemon is up and running!'
19
 
 
20
  # Build the Nginx image using the copied exdocker Dockerfile
21
  echo "Building my-nginx-app image..."
22
  docker build -f exdocker -t my-nginx-app .
@@ -31,6 +66,8 @@ echo 'Inner Nginx container started. Testing accessibility...'
31
  # Test accessibility of the inner Nginx server
32
  curl http://localhost:8080
33
 
34
- # Keep this DinD container running indefinitely
35
  echo "DinD container is running. Access Nginx at http://localhost:8080 (from host)."
36
- wait # Wait for background processes (like dockerd) to finish, keeping the container alive
 
 
 
1
+ #!/bin/bash
2
+ set -eo pipefail # Exit immediately if a command exits with a non-zero status.
3
+ # Also exit if any command in a pipeline fails.
4
 
5
+ # Ensure /usr/local/bin is in PATH for the 'docker' user
6
+ export PATH="/usr/local/bin:$PATH"
 
 
 
7
 
8
+ echo "--- Debugging Environment ---"
9
+ echo "Current user: $(whoami)"
10
+ echo "Current working directory: $(pwd)"
11
+ echo "PATH: $PATH"
12
+ echo "--- File System Checks ---"
13
+ echo "Listing contents of /usr/local/bin/"
14
+ ls -la /usr/local/bin/ || echo "ls failed in /usr/local/bin"
15
+
16
+ echo "Checking for dockerd-rootless.sh using 'which'"
17
+ which dockerd-rootless.sh || echo "dockerd-rootless.sh not found by 'which'"
18
+
19
+ echo "Checking for dockerd-rootless.sh using 'find' from root"
20
+ find / -name "dockerd-rootless.sh" 2>/dev/null || echo "dockerd-rootless.sh not found by 'find'"
21
+
22
+ echo "--- Starting Docker Daemon ---"
23
+ # Start the rootless Docker daemon in the background.
24
+ # The `docker:dind-rootless` image's default `ENTRYPOINT` is `dockerd-rootless.sh`.
25
+ # Since we are overriding the ENTRYPOINT with `start.sh`, `start.sh` must explicitly
26
+ # run `dockerd-rootless.sh`.
27
+ # We use `exec` here so that `dockerd-rootless.sh` becomes the main process,
28
+ # allowing it to correctly set up the rootless environment and `rootlesskit` re-execution.
29
+ # We then put it in the background and wait for it.
30
+
31
+ # IMPORTANT: The `dockerd-rootless.sh` script itself uses `exec rootlesskit ... $0 $@`
32
+ # This means it replaces the current shell process.
33
+ # So, we cannot simply run it with `&` and expect the rest of `start.sh` to execute.
34
+ # Instead, we need to manage the daemon's lifecycle differently.
35
+
36
+ # Let's try to run dockerd-rootless.sh directly as the primary process,
37
+ # and then use a separate mechanism to run our build/run commands.
38
+ # This is problematic for a single CMD/ENTRYPOINT.
39
+
40
+ # Alternative approach: Run dockerd-rootless.sh in the background, but use a loop to wait for its socket.
41
+ # This is the most common pattern for DinD when you need to run other commands.
42
+ echo "Attempting to run dockerd-rootless.sh in background and wait for socket..."
43
+ /usr/local/bin/dockerd-rootless.sh &
44
+ DAEMON_PID=$! # Capture the PID of the background daemon
45
 
46
  # Wait for the Docker daemon to be fully ready
47
+ echo "Waiting for Docker daemon to become available..."
48
  until docker info >/dev/null 2>&1; do
49
+ echo 'Still waiting for Docker daemon to start...'
50
  sleep 1
51
  done
52
  echo 'Docker daemon is up and running!'
53
 
54
+ echo "--- Performing Inner Docker Operations ---"
55
  # Build the Nginx image using the copied exdocker Dockerfile
56
  echo "Building my-nginx-app image..."
57
  docker build -f exdocker -t my-nginx-app .
 
66
  # Test accessibility of the inner Nginx server
67
  curl http://localhost:8080
68
 
69
+ echo "--- DinD Container Running ---"
70
  echo "DinD container is running. Access Nginx at http://localhost:8080 (from host)."
71
+
72
+ # Keep this DinD container running indefinitely by waiting on the daemon process
73
+ wait $DAEMON_PID # Wait for the dockerd-rootless.sh process to finish, which keeps the container alive