mirror of
https://github.com/DerTyp7/docker_minecraft_server_auto_starter.git
synced 2025-10-29 20:52:09 +01:00
Refactor Dockerfile and nginxHandler.py
This commit is contained in:
18
Dockerfile
18
Dockerfile
@@ -7,18 +7,6 @@ ENV PYTHONUNBUFFERED=1
|
|||||||
# Install Python and pip
|
# Install Python and pip
|
||||||
RUN apt-get update && apt-get install -y python3 python3-pip python3-venv
|
RUN apt-get update && apt-get install -y python3 python3-pip python3-venv
|
||||||
|
|
||||||
# Install Docker
|
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
apt-transport-https \
|
|
||||||
ca-certificates \
|
|
||||||
curl \
|
|
||||||
gnupg \
|
|
||||||
lsb-release && \
|
|
||||||
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && \
|
|
||||||
echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list && \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get install -y docker-ce docker-ce-cli containerd.io
|
|
||||||
|
|
||||||
# Create a virtual environment and activate it
|
# Create a virtual environment and activate it
|
||||||
RUN python3 -m venv /app/venv
|
RUN python3 -m venv /app/venv
|
||||||
ENV PATH="/app/venv/bin:$PATH"
|
ENV PATH="/app/venv/bin:$PATH"
|
||||||
@@ -33,8 +21,8 @@ WORKDIR /app
|
|||||||
RUN pip install --upgrade pip
|
RUN pip install --upgrade pip
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
# Expose port 80 for Nginx
|
# Expose port 25560 - 25570
|
||||||
EXPOSE 80
|
EXPOSE 25560-25570
|
||||||
|
|
||||||
# Start Nginx and run the Python app
|
# Start Nginx and run the Python app
|
||||||
CMD docker compose up -d --remove-orphans && service nginx start && exec python app.py
|
CMD service nginx start && exec python app.py
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
version: "3.9"
|
|
||||||
|
|
||||||
services:
|
|
||||||
mc_placeholder_starting:
|
|
||||||
container_name: mc_placeholder_starting
|
|
||||||
image: itzg/minecraft-server
|
|
||||||
ports:
|
|
||||||
- "20000:20000"
|
|
||||||
environment:
|
|
||||||
type: "PAPER"
|
|
||||||
EULA: "TRUE"
|
|
||||||
MOTD: "starting..."
|
|
||||||
MAX_PLAYERS: "0"
|
|
||||||
MAX_MEMORY: "200M"
|
|
||||||
SERVER_PORT: "20000"
|
|
||||||
ONLINE_MODE: "FALSE"
|
|
||||||
@@ -24,6 +24,7 @@ class NginxHandler:
|
|||||||
print(f.read())
|
print(f.read())
|
||||||
|
|
||||||
def setup_config_file(self, port_ip_map, current_container_ip):
|
def setup_config_file(self, port_ip_map, current_container_ip):
|
||||||
|
proxy_timeout = "300ms"
|
||||||
self.stop()
|
self.stop()
|
||||||
print('Setting up NGINX config file...')
|
print('Setting up NGINX config file...')
|
||||||
print('port_ip_map: {}'.format(port_ip_map))
|
print('port_ip_map: {}'.format(port_ip_map))
|
||||||
@@ -43,6 +44,12 @@ class NginxHandler:
|
|||||||
nginx_conf.write(' server {\n')
|
nginx_conf.write(' server {\n')
|
||||||
nginx_conf.write(' listen {}:{};\n'.format(
|
nginx_conf.write(' listen {}:{};\n'.format(
|
||||||
current_container_ip, port))
|
current_container_ip, port))
|
||||||
|
|
||||||
|
nginx_conf.write(' proxy_connect_timeout {};\n'.format(
|
||||||
|
proxy_timeout))
|
||||||
|
nginx_conf.write(' proxy_timeout {};\n'.format(
|
||||||
|
proxy_timeout))
|
||||||
|
|
||||||
nginx_conf.write(' proxy_pass upstream_{};\n'.format(port))
|
nginx_conf.write(' proxy_pass upstream_{};\n'.format(port))
|
||||||
nginx_conf.write(' }\n')
|
nginx_conf.write(' }\n')
|
||||||
nginx_conf.write('}\n')
|
nginx_conf.write('}\n')
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ networks:
|
|||||||
- subnet: 172.20.0.0/16
|
- subnet: 172.20.0.0/16
|
||||||
|
|
||||||
services:
|
services:
|
||||||
minecraft_server_auto_starter:
|
auto_starter:
|
||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
- 25565:25565
|
- 25565:25565
|
||||||
@@ -30,7 +30,7 @@ services:
|
|||||||
type: "PAPER"
|
type: "PAPER"
|
||||||
EULA: "TRUE"
|
EULA: "TRUE"
|
||||||
MOTD: "TEST1"
|
MOTD: "TEST1"
|
||||||
#! Dont change SERVER_PORT. Use PORT_IP_MAP in minecraft_server_auto_starter instead.
|
#! Dont change SERVER_PORT. Use PORT_IP_MAP in auto_starter instead.
|
||||||
#! SERVER_PORT default is "25565"
|
#! SERVER_PORT default is "25565"
|
||||||
networks:
|
networks:
|
||||||
mc_network:
|
mc_network:
|
||||||
|
|||||||
Reference in New Issue
Block a user