12
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

dockerでsudoできるユーザを追加するdockerfile

Posted at

useradd -G sudoを行う

FROM ubuntu:15.10
MAINTAINER kakkyz <kakkyz81@gmail.com>

# install sudo
RUN apt-get update && apt-get install -y sudo
# add user
RUN groupadd -g 1000 yyyyy && \
    useradd -g yyyyy -G sudo -m -s /bin/bash xxxxx && \
    echo 'xxxxx:password' | chpasswd

USER xxxxx

build

$ docker build -t kakkyz81/tmp .

run

$ docker run -it kakkyz81/tmp
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

xxxxx@4171d3e97dd6:/$ cd ~
xxxxx@4171d3e97dd6:~$ ls -la
total 20
drwxr-xr-x 2 xxxxx yyyyy 4096 Mar  9 07:41 .
drwxr-xr-x 3 root  root  4096 Mar  9 07:41 ..
-rw-r--r-- 1 xxxxx yyyyy  220 Aug 31  2015 .bash_logout
-rw-r--r-- 1 xxxxx yyyyy 3771 Aug 31  2015 .bashrc
-rw-r--r-- 1 xxxxx yyyyy  675 Aug 31  2015 .profile
xxxxx@4171d3e97dd6:~$ sudo ls -la
[sudo] password for xxxxx:
total 20
drwxr-xr-x 2 xxxxx yyyyy 4096 Mar  9 07:43 .
drwxr-xr-x 4 root  root  4096 Mar  9 07:43 ..
-rw-r--r-- 1 xxxxx yyyyy  220 Aug 31  2015 .bash_logout
-rw-r--r-- 1 xxxxx yyyyy 3771 Aug 31  2015 .bashrc
-rw-r--r-- 1 xxxxx yyyyy  675 Aug 31  2015 .profile
-rw-r--r-- 1 xxxxx yyyyy    0 Mar  9 07:43 .sudo_as_admin_successful
xxxxx@4171d3e97dd6:~$
12
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?