Skip to main content

Building an Isolated Slack Desktop Environment with Docker

Hey there! In this article, we're going to explore how to build an isolated and portable runtime environment for the Slack desktop application using Docker containers.

Why Isolate Slack?

Slack is a super popular tool for team collaboration and communication. It's great for keeping everyone in the loop, but sometimes it can run in the background for a long time. This can sometimes lead to conflicts with other applications on your system. On the other hand, Slack's updates, plugins, configuration files, etc., may also "pollute" the host system's environment. This can be a bit of a hassle!

Running Slack in a Docker container can effectively isolate it, thereby:

  • Avoiding resource contention with other applications
  • Preventing pollution of the system environment
  • Achieving a portable and consistent runtime environment
  • Facilitating backup and restoration of configurations

Dockerfile

We will build the Slack container image based on the lightweight Debian 11 (Bullseye) system. The following are the key steps:

  1. Install basic software packages: apt-transport-https, ca-certificates, curl, gnupg, etc., to prepare for adding repositories and installation.

  2. Configure language environment: Set the default locale to en_US.UTF-8.

  3. Add Slack repository: Obtain the repository key from Slack official sources and write the source address to sources.list.

  4. Install Slack: Using the apt command, install the slack-desktop package and its runtime dependencies based on the configured source.

  5. Set entry point: Set /usr/lib/slack/slack as the default execution command for the container.

The complete Dockerfile script is as follows:

FROM debian:bullseye-slim

ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8

RUN apt-get update && apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
locales \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen en_US.utf8 \
&& /usr/sbin/update-locale LANG=en_US.UTF-8

# Add the slack debian repo
RUN curl -sSL https://packagecloud.io/slacktechnologies/slack/gpgkey | apt-key add -
RUN echo "deb https://packagecloud.io/slacktechnologies/slack/debian/ jessie main" > /etc/apt/sources.list.d/slacktechnologies_slack.list

RUN apt-get update && apt-get -y install \
libasound2 \
libgtk-3-0 \
libx11-xcb1 \
libxkbfile1 \
slack-desktop \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["/usr/lib/slack/slack"]

Running the Slack Container

To run the built image, you can use the following command:

docker run --rm -it \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
--device /dev/snd \
--device /dev/dri \
--device /dev/video0 \
--group-add audio \
--group-add video \
-v "${HOME}/.slack:/root/.config/Slack" \
--ipc="host" \
--name slack \
jess/slack

This command performs the following mappings and configurations:

  • Map the host's timezone information to the container
  • Share the host's X11 Unix socket, allowing the container to run GUI applications
  • Set the container's DISPLAY environment variable to connect to the host's X Server
  • Expose audio, video, and other devices to the container
  • Map the current user's .slack directory to the container for configuration and cache storage
  • Run the container in the host's IPC namespace, allowing the use of the X Server

This way, you can safely run the Slack desktop application in an isolated and customizable container.

Summary

Docker is a great way to decouple desktop-level applications like Slack from the host system. With automatic builds based on Dockerfiles, you can be sure that Slack will run in a consistent and portable environment, no matter what your local environment looks like.