File size: 1,480 Bytes
e7dccbd
6abf46b
6723c3c
e7dccbd
 
 
a57ffa2
e7dccbd
 
 
a57ffa2
 
e7dccbd
 
a57ffa2
 
 
 
e7dccbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Use the rootless Docker-in-Docker base image
FROM docker:dind-rootless

# Set the working directory inside the container
WORKDIR /app

# Copy the Nginx app's index.html and its Dockerfile (exdocker) into this container
COPY index.html ./
COPY exdocker ./

# Switch to root user to install curl, as apk requires root privileges
USER root
RUN apk add --no-cache curl

# Switch back to the default non-root user for dind-rootless (usually 'docker')
# This is important for security and proper operation of the rootless daemon
USER docker

# Expose a port from this DinD container.
# We'll map the inner Nginx container's port 80 to this port (e.g., 8080)
# within the DinD container. Then, we can map this 8080 to the host.
EXPOSE 8080

# Define the entrypoint to start the rootless Docker daemon
ENTRYPOINT ["/usr/local/bin/dockerd-rootless.sh"]

# Define the command to execute once the daemon is up:
# 1. Wait for the Docker daemon to be ready (sleep 5 seconds).
# 2. Build the Nginx image using the copied Dockerfile (exdocker).
# 3. Run the Nginx container in detached mode, mapping its port 80
#    to port 8080 *inside this DinD container*.
# 4. Keep this DinD container running indefinitely.
CMD ["sh", "-c", "sleep 5 && \
    docker build -f exdocker -t my-nginx-app . && \
    docker run -d -p 8080:80 --name my-inner-nginx my-nginx-app && \
    echo 'Inner Nginx container started. Testing accessibility...' && \
    curl http://localhost:8080 && \
    sleep infinity"]