Docker Community Forums

Share and learn in the Docker community.

Mount volume with environment veriable

Good day all,

I am new here and new to docker so please forgive me if my question appears obvious however I have tried a google search and I am unable to find the correct answer. So I am working a my own version of docker Linux game server. I am starting with PixARK as my first game as it covers all the images I will need for future games. I have created my own steamcmd+wine image and get my game to launch however I am trying to mount a volume to a directory but the directory is a environment variable. My docker file is below:

###########################################################
# Dockerfile that builds a PixARK Linux Gameserver
###########################################################
FROM silent/steamcmd-wine:latest

LABEL maintainer="silent@silentmecha.co.za"

ENV STEAMAPPID 824360
ENV STEAMAPP PixARK
ENV STEAMAPPDIR "${HOMEDIR}/${STEAMAPP}-dedicated"

COPY src/ ${HOMEDIR}

RUN set -x \
	&& mkdir -p "${STEAMAPPDIR}" \
	&& { \
		echo '@ShutdownOnFailedCommand 1'; \
		echo '@sSteamCmdForcePlatformType windows'; \
		echo '@NoPromptForPassword 1'; \
		echo 'login anonymous'; \
		echo 'force_install_dir '"${STEAMAPPDIR}"'; \
		echo 'app_update '"${STEAMAPPID}"'; \
		echo 'quit'; \
	   } > "${HOMEDIR}/${STEAMAPP}_update.txt" \
	&& chmod +x "${HOMEDIR}/entry.sh" \
	&& chown -R "${USER}:${USER}" "${HOMEDIR}/entry.sh" "${STEAMAPPDIR}" "${HOMEDIR}/${STEAMAPP}_update.txt" \
	&& bash "${STEAMCMDDIR}/steamcmd.sh" \
		+@sSteamCmdForcePlatformType windows \
		+login anonymous \
		+force_install_dir "${STEAMAPPDIR}" \
		+app_update "${STEAMAPPID}" validate \
		+quit \
	&& su ${USER} -c \
		"wine wineboot --init"

USER ${USER}

VOLUME ${STEAMAPPDIR}

WORKDIR ${HOMEDIR}
	
CMD ["bash", "entry.sh"]

# Expose ports
EXPOSE 27015/tcp \
	27015/udp \
	27016/tcp \
	27016/udp \
	27017/tcp \
	27017/udp \
	15000/tcp \
	15000/udp \
	27020/udp

Then I build it and run it with the following run command:
docker run -dit --net=host --name=pixark-server -v pixark-server_data:${STEAMAPPDIR} silent/pixark-server

This does not work however I am not sure why it does not work. Please can someone help me?

Are your aware that the variable ${STEAMAPPDIR} is resolved on the host and whatever its value is, is used as the container target for the volume? The variable on the host and the variable in the container are not related - they just happen to have the same variable name.

You can mount volumes into any folder inside the container, even if it is not declared as a volume. Even though you used an ENV variable to declare a volume (path) inside the container, what actualy is declared is a volume using the value of the variable, not the variable name itself.