YugabyteDB Docker image

create a YugabyteDB Docker image with custom uid / gid

The default YugabyteDB Docker image from Docker Hub runs the database as a root user.

I need to run it as a non-root user and there is no release Docker image Dockerfile available in YugabyteDB repositories.

So I’ve created my own and here it is.

FROM centos:7.9.2009 as builder
ARG YB_VERSION=2.7.1.1
RUN yum update -y && yum install -y wget curl \
&& wget https://downloads.yugabyte.com/yugabyte-${YB_VERSION}-linux.tar.gz -O /yugabyte-${YB_VERSION}-linux.tar.gz
FROM centos:7.9.2009
ARG GID=1060
ARG GROUPNAME=myybuser
ARG UID=1060
ARG USERNAME=myybuser
ARG YB_VERSION=2.7.1.1
RUN groupadd -g ${GID} ${GROUPNAME} \
&& useradd -m -d /home/${USERNAME} -g ${GID} -u ${UID} -s /bin/bash ${USERNAME}
COPY --from=builder /yugabyte-${YB_VERSION}-linux.tar.gz /home/${USERNAME}/yugabyte-${YB_VERSION}-linux.tar.gz
RUN tar xvfz /home/${USERNAME}/yugabyte-${YB_VERSION}-linux.tar.gz -C /home/${USERNAME} --strip 1 \
&& /home/${USERNAME}/bin/post_install.sh \
&& chown -R ${USERNAME}:${GROUPNAME} /home/${USERNAME} \
&& ln -s /home/${USERNAME}/bin/yb-admin /usr/local/bin/yb-admin \
&& ln -s /home/${USERNAME}/bin/yb-ts-cli /usr/local/bin/yb-ts-cli \
&& ln -s /home/${USERNAME}/bin/ycqlsh /usr/local/bin/ycqlsh \
&& ln -s /home/${USERNAME}/bin/ysqlsh /usr/local/bin/ysqlsh \
&& ln -s /home/${USERNAME}/bin/yugabyted /usr/local/bin/yugabyted \
&& chown -R ${USERNAME}:${GROUPNAME} /usr/local/bin
USER ${USERNAME}
view raw Dockerfile hosted with ❤ by GitHub

To build the image, run this command:

1
2
3
4
curl --silent https://gist.githubusercontent.com/radekg/3f749cba86e91a8c88eb0e88c8b8754c/raw > Dockerfile
docker build -t yb-test:latest .
...
 => => naming to docker.io/library/yb-test:latest

Start the container:

1
docker run --rm -ti yb-test:latest bash

Run this in the the container to start the cluster:

1
[myybuser@0fb8cfa7c3d0 /]$ yugabyted start

The output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
Starting yugabyted...
✅ System checks

+--------------------------------------------------------------------------------------------------+
|                                            yugabyted                                             |
+--------------------------------------------------------------------------------------------------+
| Status              : Running. Leader Master is present                                          |
| Web console         : http://127.0.0.1:7000                                                      |
| JDBC                : jdbc:postgresql://127.0.0.1:5433/yugabyte?user=yugabyte&password=yugabyte  |
| YSQL                : bin/ysqlsh   -U yugabyte -d yugabyte                                       |
| YCQL                : bin/ycqlsh   -u cassandra                                                  |
| Data Dir            : /home/myybuser/var/data                                                    |
| Log Dir             : /home/myybuser/var/logs                                                    |
| Universe UUID       : c9e704e3-ff8b-46df-8921-6c5bbd6de2f8                                       |
+--------------------------------------------------------------------------------------------------+
🚀 yugabyted started successfully! To load a sample dataset, try 'yugabyted demo'.
🎉 Join us on Slack at https://www.yugabyte.com/slack
👕 Claim your free t-shirt at https://www.yugabyte.com/community-rewards/

That’s about it.