Skip to content

Commit 3c1ecdb

Browse files
committed
alpine add user
1 parent a6b493a commit 3c1ecdb

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

alpine/alpine-adduser/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM gliderlabs/alpine:latest
2+
3+
#-h DIR Home directory
4+
#-g GECOS GECOS field
5+
#-s SHELL Login shell
6+
#-G GRP Add user to existing group
7+
#-S Create a system user
8+
#-D Do not assign a password
9+
#-H Do not create home directory
10+
#-u UID User id
11+
12+
#-g GID Group id
13+
#-S Create a system group
14+
15+
16+
#There is no inherent difference between system groups and 'normal' groups, just like there is none between system users and regular users.
17+
#It is by convention that human users are assigned uids from a certain number (e.g. 1000) upwards, whereas system users get uids in a range below that number.
18+
19+
#RUN addgroup -g 999 app && adduser -D -G app -s /bin/sh -u 999 app
20+
21+
RUN apk add --update \
22+
python \
23+
py-pip \
24+
&& pip install flask -U \
25+
&& rm -rf /var/cache/apk/* \
26+
&& adduser -D app \
27+
&& mkdir /foo \
28+
&& chown -R app:app /foo
29+
30+
USER app
31+
32+
# add directly the jar
33+
ADD main.py /foo/main.py
34+
35+
# creates a mount point
36+
VOLUME /tmp
37+
38+
CMD python /foo/main.py
39+
40+
EXPOSE 8008

alpine/alpine-adduser/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# flask-alpine-docker
3+
4+
This example creates a non-root user in a docker image based on alpine and runs a flask server with non-root user privileges.
5+
6+
---
7+
8+
## Build using:
9+
```
10+
docker build --no-cache -t python-build:latest .
11+
```
12+
---
13+
14+
## Run using:
15+
```
16+
docker run -it --name flaskpython -p 8008:8008 python-build:latest
17+
```
18+
19+
---

alpine/alpine-adduser/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from flask import Flask
2+
app = Flask(__name__)
3+
4+
@app.route('/')
5+
def hello_world():
6+
return 'Hello World!'
7+
8+
if __name__ == '__main__':
9+
app.run('0.0.0.0',8008)

0 commit comments

Comments
 (0)