Skip to content

Commit f1182be

Browse files
ps1337xarkes
authored andcommittedJun 30, 2018
Docker: Add UID/GID mapping, Refactoring (rizinorg#557)
* docker/Dockerfile: Reduce layer count, restructure * Docker: Add UID/GID mapping
1 parent 1e6f8b9 commit f1182be

File tree

4 files changed

+45
-31
lines changed

4 files changed

+45
-31
lines changed
 

‎docker/Dockerfile

+28-27
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ LABEL maintainer "pschmied <ps1337@mailbox.org>"
44
# Dependencies
55
RUN apt-get update && \
66
apt-get -y install \
7-
curl \
8-
libqt5svg5-dev \
9-
make \
10-
qtbase5-dev \
11-
qtwebengine5-dev \
12-
unzip \
13-
wget \
14-
cmake \
15-
g++ \
16-
gcc \
17-
git-core \
18-
python3 \
19-
python3-dev \
20-
pkg-config
7+
cmake \
8+
curl \
9+
g++ \
10+
gcc \
11+
git-core \
12+
gosu \
13+
libqt5svg5-dev \
14+
make \
15+
pkg-config \
16+
python3 \
17+
python3-dev \
18+
qtbase5-dev \
19+
qtwebengine5-dev \
20+
unzip \
21+
wget
2122

2223
# Get latest cutter release
2324
WORKDIR /opt
@@ -40,26 +41,26 @@ RUN rm -rf radare2 && \
4041
wget -O radare2.zip -i - && \
4142
unzip radare2.zip && \
4243
rm radare2.zip && \
43-
mv radare-radare2* radare2
44-
45-
RUN cd radare2 && ./sys/install.sh
44+
mv radare-radare2* radare2 && \
45+
cd radare2 && ./sys/install.sh
4646

4747
# Build cutter
4848
RUN mkdir build
4949
WORKDIR /opt/cutter/build
50-
RUN cmake ../src
51-
RUN make
50+
RUN cmake ../src && \
51+
make
5252

5353
# Add r2 user
5454
RUN useradd r2
5555

56-
WORKDIR /home/r2
57-
RUN mkdir /var/sharedFolder
58-
RUN mkdir -p /home/r2/.config/radare2
59-
RUN touch /home/r2/.radare2rc
56+
# Prepare files to mount configurations later on
57+
RUN mkdir /var/sharedFolder && \
58+
mkdir -p /home/r2/.config/radare2 && \
59+
touch /home/r2/.radare2rc
6060

61-
RUN chown -R r2:r2 /var/sharedFolder
62-
RUN chown -R r2:r2 /home/r2/
63-
USER r2
61+
RUN chown -R r2:r2 /var/sharedFolder && \
62+
chown -R r2:r2 /home/r2/
6463

65-
ENTRYPOINT ["/opt/cutter/build/Cutter"]
64+
WORKDIR /home/r2
65+
ADD entrypoint.sh /usr/local/bin/entrypoint.sh
66+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

‎docker/Makefile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
SHELL := /bin/bash
22

3-
43
# The directory of this file
54
DIR := $(shell echo $(shell cd "$(shell dirname "${BASH_SOURCE[0]}" )" && pwd ))
65

6+
# The local users UID/GID
7+
LUID := $(shell id -u)
8+
LGID := $(shell id -g)
9+
710
# To mount a specific binary using BINARY=/absolute/path/to/binary
811
ifdef BINARY
912
MOUNTFLAGS += -v $(BINARY):/home/r2/$(shell basename $(BINARY)):ro
@@ -41,10 +44,11 @@ run: ## Run container
4144
sudo docker run \
4245
-it \
4346
--name $(CONTAINER_NAME) \
44-
--cap-drop=ALL \
4547
--cap-add=SYS_PTRACE \
4648
-e DISPLAY=$$DISPLAY \
4749
-e XAUTHORITY=$$XAUTH \
50+
-e LOCAL_USER_ID=$(LUID) \
51+
-e LOCAL_GROUP_ID=$(LGID) \
4852
-v $$XSOCK:$$XSOCK:ro \
4953
-v $$XAUTH:$$XAUTH \
5054
$(MOUNTFLAGS) \

‎docker/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Docker Configuration for Cutter
22

3-
These files provide an easy way to deploy *Cutter* in a Docker container. After additional configuration you may want to apply to the `Makefile`, execute `make run`. By default, the *Cutter* image on [Docker Hub](https://hub.docker.com/r/radareorg/cutter/) will be used along with additional capability, X and mount settings:
3+
These files provide an easy way to deploy *Cutter* in a Docker container. After additional configuration you may want to apply to the `Makefile`, execute `make run`. By default, the *Cutter* image on [Docker Hub](https://hub.docker.com/r/radareorg/cutter/) will be used along with additional UID, capability, X and mount settings:
44

55
- Xauthority settings which avoid using potentially insecure `xhost` directives. The settings have been adapted from [this post](https://stackoverflow.com/questions/16296753/can-you-run-gui-apps-in-a-docker-container/25280523#25280523).
66
- Mount directives to mount a shared folder and radare2 configuration files.
7-
- Capability dropping to only use `SYS_PTRACE`.
7+
- The UID and GID of the user executing `make run` will also be used for the internal container user to avoid permission problems when sharing files.
88

99
## Mounting and Using a Specific Binary
1010

‎docker/entrypoint.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
USERNAME="r2"
3+
4+
echo "Cutter: Starting with UID:GID $LOCAL_USER_ID:$LOCAL_GROUP_ID"
5+
usermod -u $LOCAL_USER_ID $USERNAME
6+
usermod -g $LOCAL_GROUP_ID $USERNAME
7+
export HOME=/home/$USERNAME
8+
9+
exec gosu $USERNAME "/opt/cutter/build/Cutter" $@

0 commit comments

Comments
 (0)
Please sign in to comment.