update ubuntu dev container

adjust build user
This commit is contained in:
xfy
2024-06-25 17:08:01 +08:00
parent 2a54c112a0
commit dff770a5c1
4 changed files with 29 additions and 7 deletions

View File

@ -1,9 +1,14 @@
FROM ubuntu:noble
VOLUME [ "/etc/group" ]
VOLUME [ "/etc/passwd" ]
VOLUME [ "/etc/shadow" ]
VOLUME [ "/etc/sudoers.d" ]
RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/ubuntu.sources \
&& sed -i 's@//.*security.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/ubuntu.sources \
&& apt-get update -y \
&& apt-get install -y git ninja-build gettext cmake unzip curl build-essential sudo zsh htop \
&& apt-get install -y git ninja-build gettext cmake unzip curl build-essential sudo zsh htop vim \
# install neovim
&& cd /opt && git clone --depth 1 https://gitee.com/mirrors/neovim && cd neovim \
&& make CMAKE_BUILD_TYPE=Release \
@ -12,8 +17,12 @@ RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/
&& rm -rf /var/lib/apt/lists/*
ARG USER=xfy
RUN useradd --groups sudo --no-create-home --shell /bin/bash ${USER} \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
ARG USER_ID
ARG GROUP_ID
# RUN addgroup --gid $GROUP_ID ${USER} \
RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID ${USER} \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USER} \
&& chmod 0440 /etc/sudoers.d/${USER} \
&& usermod -s "$(which zsh)" ${USER}
USER ${USER}

View File

@ -1,5 +1 @@
# Dev container with ubuntu
```shell
docker build --progress=plain -t ubuntu-dev -f dockerfiles/ubuntu/Dockerfile .
```

6
dockerfiles/ubuntu/build.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/env bash
docker build --progress=plain \
--build-arg USER_ID=$(id -u $USER) \
--build-arg GROUP_ID=$(id -g $USER) \
-t ubuntu-dev -f dockerfiles/ubuntu/Dockerfile .

11
dockerfiles/ubuntu/start.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/env bash
docker run --rm -it --name=ubuntu-dev \
--user $UID:$GID \
--workdir="/home/$USER" \
--volume="/etc/group:/etc/group:ro" \
--volume="/etc/passwd:/etc/passwd:ro" \
--volume="/etc/shadow:/etc/shadow:ro" \
--volume="/etc/sudoers.d/:/etc/sudoers.d/" \
-v $SSH_AUTH_SOCK:/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent \
ubuntu-dev