FROM ubuntu:20.04 Update package sources and install necessary packages RUN apt-get…
- User
FROM ubuntu:20.04
Update package sources and install necessary packages
RUN apt-get update && apt-get install -y
wget
bzip2
locales
python3
python3-pip
&& rm -rf /var/lib/apt/lists/*Generate and set locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen &&
locale-gen ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8Set working directory
WORKDIR /teamspeak
Download and extract the TeamSpeak server
RUN wget https://files.teamspeak-services.com/releases/server/3.13.7/teamspeak3-server_linux_amd64-3.13.7.tar.bz2
&& tar xvf teamspeak3-server_linux_amd64-3.13.7.tar.bz2
&& rm teamspeak3-server_linux_amd64-3.13.7.tar.bz2
&& touch teamspeak3-server_linux_amd64/.ts3server_license_acceptedCreate a non-root user for running the server
RUN useradd -m teamspeak
Change ownership of the TeamSpeak server files to the 'teamspeak' user
RUN chown -R teamspeak:teamspeak teamspeak3-server_linux_amd64
Set environment variable for license acceptance
ENV TS3SERVER_LICENSE=accept
Install FastAPI and uvicorn
RUN pip3 install fastapi uvicorn
Expose necessary ports
EXPOSE 9987/udp 10011 30033 7860
Switch to the 'teamspeak' user
USER teamspeak
Copy the FastAPI application to the container
COPY --chown=teamspeak:teamspeak app.py /teamspeak/
Set the working directory to the server's directory
WORKDIR /teamspeak/teamspeak3-server_linux_amd64
Start the FastAPI app using uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
from fastapi import FastAPI import subprocess
app = FastAPI()
@app.get("/start-server") def start_server(): try: # Run the TeamSpeak server command command = ["./ts3server_minimal_runscript.sh"] result = subprocess.run(command, cwd="/teamspeak/teamspeak3-server_linux_amd64", stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# Capture the output if result.returncode == 0: return {"status": "Server started successfully", "output": result.stdout} else: return {"status": "Failed to start server", "error": result.stderr} except Exception as e: return {"status": "Error", "error": str(e)}ERROR: Error loading ASGI app. Could not import module "app".
- Assistant