Newbie here! I started off with this command which allows me to build Alpine versions of software using musl. It all works as expected except that the container written files annoyingly show up as root files on the host:
$ docker run -it --privileged --rm -v `pwd`:/extern alpine:3.11.0 sh
So I came up with this command line which automates installing all the Alpine packages as well as ‘borrowing’ the users and passwords from the Ubuntu host, and allowing the container to build the software as my regular non-root user, which also means that the container files written show up as regular user files on the host:
$ docker run -it --privileged --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --rm -v `pwd`:/extern -v /etc/passwd:/etc/passwd:ro -v /etc/shadow:/etc/shadow:ro -v /etc/sudoers:/etc/sudoers:ro alpine:3.11.0 sh -c "apk update ; apk add sudo bash shadow ; mkdir /home/$USER ; groupadd sudo ; apk add gdb gcc libc-dev coreutils make perl automake autoconf libtool pkgconfig zlib-static zlib-dev expat-static openssl-libs-static openssl-dev ; su - $USER"
Question #1: Is there a downside to ‘borrowing’ like this? And is there an easier / better way to achieve the same results?
The only issue I have noticed is that gdb fails to work and upon running will silently crash and exit the container:
$ gdb --silent --args ls
Reading symbols from ls...
(No debugging symbols found in ls)
(gdb) run
Starting program: /bin/ls
simon@ubuntu:~/$ # <-- silently exited container here!
Same thing happens using sudo:
$ sudo gdb --silent --args ls
...
[sudo] password for simon:
Reading symbols from ls...
(No debugging symbols found in ls)
(gdb) run
Starting program: /bin/ls
simon@ubuntu:~/$ # <-- silently exited container here!
Note: If I run gdb as root using the top docker command and not ‘borrowing’ host users then gdb works as expected:
/ # gdb --silent --args ls
Reading symbols from ls...
(No debugging symbols found in ls)
(gdb) run
Starting program: /bin/ls
bin dev etc extern home lib media mnt opt proc root run sbin srv sys tmp usr var
[Inferior 1 (process 12) exited normally]
(gdb) quit
/ #
Question #2: Why is gdb apparently crashing docker like this, and can how can I get it to work?
Environment:
$ lsb_release -a 2>&1 | egrep Description
Description: Ubuntu 19.10
$ docker -v
Docker version 19.03.2, build 6a30dfca03