From fac528684f1f2cec60fddfc0f3b5c3330ad35cf9 Mon Sep 17 00:00:00 2001 From: whaffman Date: Sat, 5 Jul 2025 13:05:19 +0200 Subject: [PATCH] docker is working onion site reachable from host --- Dockerfile | 38 +++++++++++++++++++++++++++++++------- nginx.conf | 24 +++++++++++++++++------- sshd_config | 5 +---- start.sh | 20 +++++++++++++++++++- torrc | 3 --- 5 files changed, 68 insertions(+), 22 deletions(-) mode change 100644 => 100755 start.sh diff --git a/Dockerfile b/Dockerfile index 0155066..3480ad0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,16 +2,40 @@ FROM alpine:3.20 RUN apk update && \ apk upgrade && \ - apk add --no-cache nginx, openssh, tor \ - && rm -rf /var/cache/apk/* + apk add --no-cache nginx tor openssh && \ + rm -rf /var/cache/apk/* + +# Setup SSH + +RUN mkdir -p /var/run/sshd && \ + ssh-keygen -A && \ + echo "root:password" | chpasswd + +COPY sshd_config /etc/ssh/sshd_config + +# Setup Nginx +RUN mkdir -p /var/www/html && \ + mkdir -p /var/log/nginx && \ + mkdir -p /run/nginx && \ + chown -R nginx:nginx /var/www/html && \ + chown -R nginx:nginx /var/log/nginx && \ + chown -R nginx:nginx /run/nginx COPY nginx.conf /etc/nginx/nginx.conf -COPY torrc /etc/tor/torrc -COPY sshd_config /etc/ssh/sshd_config -COPY index.html /var/www/html/index.html -COPY entrypoint.sh /entrypoint.sh +# Setup Tor +RUN mkdir -p /var/lib/tor && \ + mkdir -p /var/log/tor + +COPY torrc /etc/tor/torrc + +# Copy the index.html and entrypoint script +COPY index.html /var/www/html/index.html + +# Copy the entrypoint script and make it executable +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh EXPOSE 4242 -CMD ["sh", "-c", "nginx && tor -f /etc/tor/torrc"] +CMD ["/entrypoint.sh"] diff --git a/nginx.conf b/nginx.conf index c11f5ed..836a23b 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,10 +1,20 @@ -server { - listen 80; - server_name +events { + worker_connections 1024; +} +http +{ + include mime.types; + default_type application/octet-stream; - location / { + server { + listen 80; root /var/www/html; - index index.html index.htm; - try_files $uri $uri/ =404; + index index.html; + server_name localhost; + + location / { + try_files $uri $uri/ =404; + } } -} \ No newline at end of file +} + diff --git a/sshd_config b/sshd_config index be1eed2..a3dcc7b 100644 --- a/sshd_config +++ b/sshd_config @@ -3,8 +3,5 @@ Port 4242 PermitRootLogin yes PasswordAuthentication yes -ChallengeResponseAuthentication no UsePAM yes -X11Forwarding no -AllowTcpForwarding no -PermitEmptyPasswords no + diff --git a/start.sh b/start.sh old mode 100644 new mode 100755 index be99a6a..78a990c --- a/start.sh +++ b/start.sh @@ -3,8 +3,26 @@ IMAGE_NAME="ft_onion_image" CONTAINER_NAME="ft_onion_container" +#remove any existing container with the same name +if [ "$(docker ps -aq -f name=$CONTAINER_NAME)" ]; then + docker rm -f $CONTAINER_NAME +fi + # Build the Docker image docker build -t $IMAGE_NAME -f Dockerfile . # Run the Docker container -docker run --name $CONTAINER_NAME -d $IMAGE_NAME -p 4242:4242 --restart unless-stopped \ No newline at end of file +docker run --name $CONTAINER_NAME -d -p 4242:4242 --restart unless-stopped $IMAGE_NAME + +# Wait for the container to start +echo "Waiting for the container to start..." +sleep 5 +# Check if the container is running +if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]; then + echo "Container $CONTAINER_NAME is running." + docker exec $CONTAINER_NAME cat /var/lib/tor/hidden_service/hostname +else + echo "Failed to start container $CONTAINER_NAME." + exit 1 +fi + diff --git a/torrc b/torrc index 1a6f2f4..ec79556 100644 --- a/torrc +++ b/torrc @@ -1,6 +1,3 @@ # Basic torrc configuration - -SocksPort 9050 - HiddenServiceDir /var/lib/tor/hidden_service/ HiddenServicePort 80 127.0.0.1:80 \ No newline at end of file