dockerdind / Dockerfile
memex-in's picture
Update Dockerfile
a57ffa2 verified
raw
history blame
1.48 kB
# 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"]