Skip to content

Commit 8bd55b0

Browse files
author
js-jslog
committed
Specify uid & gid for mapping and add sudo group
1 parent 151df3c commit 8bd55b0

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ RUN apt-get update && apt-get install -y -q --no-install-recommends \
3232
mysql-client \
3333
python \
3434
postgresql postgresql-contrib \
35+
sudo \
3536
&& rm -rf /var/lib/apt/lists/*
3637

3738
# Install docker ce so that host docker instances can be manipulated from this env
@@ -60,7 +61,9 @@ RUN add-apt-repository ppa:jonathonf/vim -y \
6061

6162
# Create developer user under which all development within the container
6263
# will be performed
63-
RUN useradd --create-home --shell /bin/bash developer
64+
RUN groupadd --gid 1000 developer
65+
RUN useradd --create-home --shell /bin/bash --uid 1000 --gid 1000 developer
66+
RUN usermod --append --groups sudo developer && echo "developer:developer" | chpasswd
6467
USER developer
6568

6669
# Install users vim customisations. This requires that the .vimrc
@@ -115,4 +118,4 @@ COPY --chown=developer:developer templates/webpack-es6/ /home/developer/template
115118
COPY --chown=developer:developer dotfiles/.gitignore /home/developer/templates/webpack-es6/.
116119
COPY --chown=developer:developer dotfiles/.eslintrc.json /home/developer/templates/webpack-es6/.
117120

118-
LABEL version="2.1.1"
121+
LABEL version="2.1.2"

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,49 @@
11
# development-env
22
The files to build a docker container with the applications I use for development
33

4-
# Clone
4+
# Important
5+
The running image defaults to a user named "developer" with a uid of 1000.
6+
7+
You will be running the container with the idea of having "developer" map directly to your user so that it can modify your files. If your user is not uid 1000 then you will need to make use of the docker `userns-remap` feature: https://docs.docker.com/engine/security/userns-remap/
8+
9+
Configuration here requires that you modify the `/etc/subuid` and `/etc/subgid` files to map 1000 in the container to whatever your user uid is in the host.
10+
11+
## eg uid 1010
12+
If your uid is 1010 then you will need to make sure that the uid's in the container are staggard by 10 in relation to your host. One way to achieve this is to start your `/etc/subuid` mappings from 9:
13+
14+
```
15+
youruser:10:1000 # 0 in the container will map to 10 in the host
16+
```
17+
18+
But this will mean that the root user (0) in the container will map to uid 9 in the host. I have made the "developer" user part of the sudo group so that we have the freedom to do whatever we want with the container. It is better to have 2 mappings with a 10 digit gap built in:
19+
20+
```
21+
youruser:0:1000 # 0 - 999 inclusive
22+
youruser:1010:1000 # 1000 in the container will map to 1010 in the host
23+
```
24+
25+
## gid
26+
A similar process needs to be performed for the `/etc/subgid` file.
27+
28+
## Docker daemon config
29+
See the instructions in the link above to configure the daemon to run with this subordinate config in mind.
30+
31+
## Motivation
32+
The purpose of creating a non-root user is not for security reasons. This is why I encourage the mapping of `youruser:0:...`. The purpose is becuase many applications don't run properly under root.
33+
34+
# Usage
35+
## Clone
536
```
637
git clone --recursive [email protected]:js-jslog/development-env.git
738
```
839

9-
# Build
40+
## Build
1041
```
1142
docker build -t jslog/development-env --build-arg http_proxy --build-arg https_proxy --build-arg HTTP_PROXY --build-arg HTTPS_PROXY .
1243
```
1344

14-
# Run
45+
## Run
1546
```
1647
docker inspect jslog/development-env | grep runcommand
1748
```
49+

0 commit comments

Comments
 (0)