fixed the Dockerfile, aperently the server has to be installed at runtime and there was also an issue with permissions which can be fixed by manually creating the direcotry data with the correct permissions. If you dont do this it will install in the default directory.

There is currently an issue with the server crashing everytime i try to join, no idea why it happens...
This commit is contained in:
bacalhau 2025-11-04 12:00:59 +00:00
parent 2084cfdf92
commit a7001cbac7
2 changed files with 17 additions and 33 deletions

View file

@ -1,17 +1,18 @@
############################################################ ############################################################
# Dockerfile that contains SteamCMD # Counter-Strike dedicated server
############################################################ ############################################################
FROM debian:bookworm-slim as build_stage FROM debian:bookworm-slim
LABEL maintainer="admin@based.pt" LABEL maintainer="admin@based.pt"
ARG PUID=1000
ENV USER steam ARG PUID=1000
ENV HOMEDIR "/home/${USER}" ENV USER=steam \
ENV STEAMCMDDIR "${HOMEDIR}/steamcmd" HOMEDIR=/home/steam \
STEAMCMDDIR=/home/steam/steamcmd \
PORT=27015 \
DATADIR=/data
RUN set -x \ RUN set -x \
# Install, update & upgrade packages
&& apt-get update \ && apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \ && apt-get install -y --no-install-recommends --no-install-suggests \
lib32stdc++6=12.2.0-14+deb12u1 \ lib32stdc++6=12.2.0-14+deb12u1 \
@ -22,9 +23,9 @@ RUN set -x \
locales=2.36-9+deb12u13 \ locales=2.36-9+deb12u13 \
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \ && sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
&& dpkg-reconfigure --frontend=noninteractive locales \ && dpkg-reconfigure --frontend=noninteractive locales \
# Create unprivileged user
&& useradd -u "${PUID}" -m "${USER}" \ && useradd -u "${PUID}" -m "${USER}" \
# Download SteamCMD, execute as user && mkdir -p "${STEAMCMDDIR}" "${DATADIR}" \
&& chown -R "${USER}:${USER}" "${HOMEDIR}" "${DATADIR}" \
&& su "${USER}" -c \ && su "${USER}" -c \
"mkdir -p \"${STEAMCMDDIR}\" \ "mkdir -p \"${STEAMCMDDIR}\" \
&& curl -fsSL 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz' | tar xvzf - -C \"${STEAMCMDDIR}\" \ && curl -fsSL 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz' | tar xvzf - -C \"${STEAMCMDDIR}\" \
@ -37,34 +38,14 @@ RUN set -x \
&& ln -s \"${STEAMCMDDIR}/linux64/steamclient.so\" \"${HOMEDIR}/.steam/sdk64/steamclient.so\" \ && ln -s \"${STEAMCMDDIR}/linux64/steamclient.so\" \"${HOMEDIR}/.steam/sdk64/steamclient.so\" \
&& ln -s \"${STEAMCMDDIR}/linux64/steamcmd\" \"${STEAMCMDDIR}/linux64/steam\" \ && ln -s \"${STEAMCMDDIR}/linux64/steamcmd\" \"${STEAMCMDDIR}/linux64/steam\" \
&& ln -s \"${STEAMCMDDIR}/steamcmd.sh\" \"${STEAMCMDDIR}/steam.sh\"" \ && ln -s \"${STEAMCMDDIR}/steamcmd.sh\" \"${STEAMCMDDIR}/steam.sh\"" \
# Symlink steamclient.so; So misconfigured dedicated servers can find it
&& ln -s "${STEAMCMDDIR}/linux64/steamclient.so" "/usr/lib/x86_64-linux-gnu/steamclient.so" \ && ln -s "${STEAMCMDDIR}/linux64/steamclient.so" "/usr/lib/x86_64-linux-gnu/steamclient.so" \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
FROM build_stage AS steamcmd
###########################################################
# HALF-LIFE SERVER
##########################################################
FROM steamcmd AS hlds
# Define variables
ENV STEAMAPPID 90
ENV STEAMAPPDIR "data/hlds"
ENV PORT 27015
USER ${USER} USER ${USER}
WORKDIR ${HOMEDIR} WORKDIR ${HOMEDIR}
# Install Half-Life Dedicated Server (HLDS) for Counter-Strike EXPOSE ${PORT}/udp
RUN mkdir -p ${STEAMAPPDIR} \ VOLUME ["/data"]
&& ${STEAMCMDDIR}/steamcmd.sh +force_install_dir ${STEAMAPPDIR} +login anonymous +app_update 90 +quit
# Expose necessary ports for the game ENTRYPOINT ["/bin/bash", "-c", "/home/steam/steamcmd/steamcmd.sh +force_install_dir /data +login anonymous +app_set_config 90 mod cstrike +app_update 90 validate +quit && cd /data && exec bash hlds_run -game cstrike -console +ip 0.0.0.0 -port ${PORT}"]
EXPOSE ${PORT}
# Run HLDS with the Counter-Strike mod
ENTRYPOINT ["${STEAMAPPDIR}/hlds_run", "-game", "cstrike", "-console", "-port", "${PORT}", "-steam_dir", "${STEAMCMDDIR}", "-steamcmd_script", "${STEAMCMDDIR}/steamcmd.sh"]

View file

@ -4,8 +4,11 @@ services:
counter-strike: counter-strike:
build: . build: .
container_name: counter-strike container_name: counter-strike
stop_signal: SIGKILL
ports: ports:
- "27016:27015/udp" - "27016:27016/udp"
environment:
- PORT=27016
volumes: volumes:
- ./data:/data - ./data:/data
restart: always restart: always