Spaces:
Build error
Build error
Download Dockerfile from smodusermc/MC: direct link, hf CLI and curl.
- Browser
- Download file 4.92 kB
-
https://huggingface.co/spaces/smodusermc/MC/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/smodusermc/MC/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/smodusermc/MC/resolve/main/Dockerfile
4.92 kB
| FROM python:3.11-slim-bookworm | |
| # ----------------------------------------------------- | |
| # Set Environment Variables | |
| # ----------------------------------------------------- | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV MINECRAFT_SERVER_DIR=/app/minecraft_server | |
| ENV SERVER_JAR_NAME=server.jar | |
| # NOTE: Adjust these memory values if your environment has more or less RAM. | |
| ENV MAX_MEMORY=10G | |
| ENV MIN_MEMORY=1G | |
| ENV WEB_PORT=7860 | |
| ENV SERVER_PORT=25565 | |
| # ----------------------------------------------------- | |
| # 1. Install core system dependencies | |
| # ----------------------------------------------------- | |
| RUN apt-get update && apt-get install -y \ | |
| curl \ | |
| wget \ | |
| unzip \ | |
| zip \ | |
| screen \ | |
| procps \ | |
| net-tools \ | |
| ca-certificates \ | |
| file \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # ----------------------------------------------------- | |
| # 2. CRITICAL FIX: Create mcuser and Directories/Permissions | |
| # This must be done before the 'chown' commands in the playit block. | |
| # ----------------------------------------------------- | |
| # Create app user and directories | |
| RUN groupadd -r mcuser -g 1000 && \ | |
| useradd -r -u 1000 -g mcuser mcuser | |
| WORKDIR /app | |
| # Create necessary directories | |
| RUN mkdir -p ${MINECRAFT_SERVER_DIR} \ | |
| ${MINECRAFT_SERVER_DIR}/mods \ | |
| ${MINECRAFT_SERVER_DIR}/world \ | |
| ${MINECRAFT_SERVER_DIR}/config \ | |
| ${MINECRAFT_SERVER_DIR}/logs \ | |
| /app/backups \ | |
| /app/uploads \ | |
| /app/static \ | |
| /app/templates \ | |
| && chown -R mcuser:mcuser /app | |
| # ----------------------------------------------------- | |
| # 3. Install PlayIt.gg Agent (DIRECT DOWNLOAD & VERIFICATION) 🔑 | |
| # ----------------------------------------------------- | |
| USER root | |
| # We keep curl install/removal here for efficiency if it wasn't installed above | |
| RUN apt-get update && \ | |
| apt-get install -y curl --no-install-recommends && \ | |
| curl -L -o /usr/local/bin/playit https://github.com/playit-cloud/playit-agent/releases/latest/download/playit-linux-x86-64 && \ chmod +x /usr/local/bin/playit && \ | |
| chown mcuser:mcuser /usr/local/bin/playit && \ | |
| apt-get remove -y curl && \ | |
| apt-get clean && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # ----------------------------------------------------- | |
| # 4. Install Java (Temurin-21) | |
| # ----------------------------------------------------- | |
| # Note: Since curl is already installed, the first line of the original Java install is redundant. | |
| RUN apt-get update && apt-get install -y gnupg dirmngr && rm -rf /var/lib/apt/lists/* | |
| RUN mkdir -p /etc/apt/keyrings && \ | |
| wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | tee /etc/apt/keyrings/adoptium.asc && \ | |
| echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list && \ | |
| apt-get update && \ | |
| apt-get install -y temurin-21-jdk && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # Set Java environment | |
| ENV JAVA_HOME=/usr/lib/jvm/temurin-21-jdk-amd64 | |
| ENV PATH="${JAVA_HOME}/bin:${PATH}" | |
| # ----------------------------------------------------- | |
| # 5. Install Python Dependencies | |
| # ----------------------------------------------------- | |
| # Copy requirements first for caching | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Force a rebuild when the installation changes | |
| ENV CACHE_BUSTER=20251207_v33 | |
| # Copy application files (including the server.jar and other files) | |
| # The CHOWN is redundant here since the final chown -R /app was done earlier | |
| COPY . . | |
| # --- Minecraft Setup --- | |
| # Uses ENV vars for cleaner execution | |
| RUN cp /app/${SERVER_JAR_NAME} ${MINECRAFT_SERVER_DIR}/${SERVER_JAR_NAME} && \ | |
| echo "eula=true" > ${MINECRAFT_SERVER_DIR}/eula.txt && \ | |
| chown -R mcuser:mcuser ${MINECRAFT_SERVER_DIR} | |
| # --- End Setup --- | |
| # Create default server.properties | |
| RUN printf 'server-port=25565\n\ | |
| max-players=2\n\ | |
| online-mode=false\n\ | |
| enable-command-block=false\n\ | |
| spawn-protection=0\n\ | |
| view-distance=6\n\ | |
| simulation-distance=8\n\ | |
| motd=\\u00A7b\\u00A7lHF Spaces MC Server\\u00A7r - \\u00A7aOnline\n\ | |
| difficulty=normal\n\ | |
| gamemode=survival\n\ | |
| level-name=world\n\ | |
| pvp=true\n\ | |
| allow-flight=true\n\ | |
| white-list=false\n\ | |
| enforce-whitelist=false\n\ | |
| max-tick-time=60000\n\ | |
| network-compression-threshold=256\n\ | |
| enable-status=true\n\ | |
| enable-query=false\n' > ${MINECRAFT_SERVER_DIR}/server.properties | |
| # Expose ports (7860 for web UI, 25565 for internal MC server) | |
| EXPOSE ${WEB_PORT} ${SERVER_PORT} | |
| # ----------------------------------------------------- | |
| # 6. Prepare Start Script | |
| # ----------------------------------------------------- | |
| # Assuming 'start.sh' is copied in the previous COPY . . command | |
| RUN chmod +x ./start.sh | |
| # Switch to non-root user | |
| USER mcuser | |
| # ----------------------------------------------------- | |
| # 7. Update Start command to use the shell wrapper | |
| # ----------------------------------------------------- | |
| CMD ["./start.sh"] |