Skip to content

Commit 38e57a1

Browse files
committed
Running image as normal user instead of root
1 parent c3911df commit 38e57a1

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

Dockerfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@ MAINTAINER MagicVision Team
44

55
RUN apt-get update -y
66

7+
# Add a normal user with sudo permission
8+
RUN adduser --disabled-password --gecos "" ubuntu && echo "ubuntu ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu
9+
710
# Install nvm
811
RUN apt-get install -y curl build-essential libssl-dev man && \
9-
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
12+
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | su - ubuntu -c sh && \
13+
echo 'export NVM_DIR="$HOME/.nvm"' >> /etc/profile && \
14+
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' >> /etc/profile
1015

1116
# Install node.js 4.1.0
12-
RUN bash -ic "nvm install 4.1.0" && \
13-
bash -ic "nvm alias default 4.1.0" && \
14-
bash -ic "nvm use 4.1.0"
17+
RUN su - ubuntu -c "nvm install 4.1.0" && \
18+
su - ubuntu -c "nvm alias default 4.1.0" && \
19+
su - ubuntu -c "nvm use 4.1.0"
1520

1621
# Use Taobao node mirror and npm registry
1722
ENV NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node
18-
RUN /root/.nvm/v4.1.0/bin/npm config set registry http://registry.npm.taobao.org
23+
RUN su - ubuntu -c "npm config set registry http://registry.npm.taobao.org"
1924

2025
# Provisioning gitlab CA
2126
ADD gitlab-CA.crt /usr/local/share/ca-certificates/
22-
RUN update-ca-certificates
27+
RUN sudo update-ca-certificates
2328

2429
# Install docker-cli
2530
# See https://github.com/docker-library/docker/blob/bb15fc25bbd4f51a880cf02f91eab447b1083b75/1.8/Dockerfile
@@ -40,7 +45,7 @@ RUN apt-get install -y git
4045
RUN apt-get install -y python
4146

4247
# Install bower
43-
RUN apt-get install -y libkrb5-dev && bash -ic "npm install -g bower"
48+
RUN apt-get install -y libkrb5-dev && su - ubuntu -c "npm install -g bower"
4449

4550
# Use tsinghua ubuntu mirror
4651
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty main restricted universe multiverse" > /etc/apt/sources.list && \
@@ -51,4 +56,8 @@ RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty main restricted
5156
apt-get update -y
5257

5358
COPY ./entrypoint.sh /
59+
RUN chmod 755 /entrypoint.sh
60+
61+
# Run as a normal user
62+
USER ubuntu
5463
ENTRYPOINT ["/entrypoint.sh"]

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ test:
99
docker run --rm magicvision/nodejs-dev git --version
1010
docker run --rm magicvision/nodejs-dev python --version
1111
docker run --rm magicvision/nodejs-dev bower --version
12+
docker run --rm magicvision/nodejs-dev sudo whoami

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- git 1.9.1
1616
- python 2.7.6
1717
- bower 1.6.5
18+
- Run commands as a normal user named *ubuntu* with sudo permission
1819

1920
[docker:dind]: https://hub.docker.com/_/docker/#
2021
[Saas]: https://github.com/sass/sass

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# activate nvm
4-
export NVM_DIR="/root/.nvm"
4+
export NVM_DIR="$HOME/.nvm"
55
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
66

77
# if we have "--link some-docker:docker" and not DOCKER_HOST, let's set DOCKER_HOST automatically

0 commit comments

Comments
 (0)