Using sound in a docker environment - githeim/windheim_archive GitHub Wiki

Using sound in a docker environment

Here's how to access sound in a Docker container.

prerequisites for sound

RUN apt install alsa-utils alsa-oss libasound2-dev libasound2-plugins pulseaudio-utils pulseaudio libpulse0 

์ปจํ…Œ์ด๋„ˆ์™€ host ๋ชจ๋‘ ์„ค์น˜

docker run command

๋‹ค์Œ๊ณผ ๊ฐ™์ด docker run์˜ ๋ช…๋ น์–ด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค. pulse audio๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

-e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
-v ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native \
-v ~/.config/pulse/cookie:/home/ubuntu/.config/pulse/cookie:ro \
-e PULSE_COOKIE=/home/ubuntu/.config/pulse/cookie \
--device /dev/snd \
--group-add $(getent group audio | cut -d: -f3) \

์˜ˆ

sudo docker run -it --name $CONTAINER_NAME  \
  --privileged \
  --env="DISPLAY=${DISPLAY}" \
  --ipc=host \
  --net=host \
  -e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
  -v ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native \
  -v ~/.config/pulse/cookie:/home/ubuntu/.config/pulse/cookie:ro \
  -e PULSE_COOKIE=/home/ubuntu/.config/pulse/cookie \
  --device /dev/snd \
  --group-add $(getent group audio | cut -d: -f3) \
  -v $DOCKER_SHARED_DIR:/home/ubuntu/share \
  $DOCKER_IMG_NAME /bin/bash

ALSA ์ง์ ‘ ์ ‘๊ทผ ์˜ˆ

sudo docker run -it --name $CONTAINER_NAME  \
  --privileged \
  --env="DISPLAY=${DISPLAY}" \
  --ipc=host \
  --net=host \
  --device /dev/snd \
  --group-add $(getent group audio | cut -d: -f3) \
  -v /etc/asound.conf:/etc/asound.conf:ro \
  -v $DOCKER_SHARED_DIR:/home/ubuntu/share \
  $DOCKER_IMG_NAME /bin/bash