deluan / zsh-in-docker

Install Zsh, Oh-My-Zsh and plugins inside a Docker container with one line!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

non root user install failed: sudo: no tty present and no askpass program specified

nickfan opened this issue · comments

commented

dockerfile segment:

ARG DEBIAN_FRONTEND=noninteractive
ENV DEBIAN_FRONTEND=${DEBIAN_FRONTEND}
RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
    sudo net-tools iputils-ping iproute2 telnet curl wget nano procps

RUN addgroup www && adduser --shell /bin/zsh --home /home/www --gecos "" --ingroup www --disabled-password www
USER www
# Default powerline10k theme, no plugins installed
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)"

#20 0.833 ###### Installing dependencies for ubuntu
#20 0.837 /usr/bin/sudo
#20 0.854 sudo: no tty present and no askpass program specified
------
executor failed running [/bin/bash -c sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)" --     -p git     -p ssh-agent     -p z     -p autojump     -p history     -p last-working-dir     -p docker     -p github     -p jsontools     -p node     -p npm     -p golang     -p tmux     -p tmuxinator     -p catimg     -p https://github.com/zsh-users/zsh-autosuggestions
 -p https://github.com/zsh-users/zsh-completions     -p https://github.com/zsh-users/zsh-syntax-highlighting     -a 'export ZSH_DISABLE_COMPFIX=true'     -a 'HIST_STAMPS="yyyy-mm-dd"'     -a 'autoload -U compinit && compinit'     -a 'export ZSH_TMUX_AUTOSTART=false'     -a 'export ZSH_TMUX_AUTOCONNECT=false'     -a 'zstyle :omz:plugins:ssh-agent agent-forwarding on'     -a 'if [ -f \$HOME/.myenvset ]; then source \$HOME/.myenvset;fi'     -a '[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh'     -a 'if [ "\$TERM" = "xterm-256color" ] && [ -z "\$INSIDE_EMACS" ]; then test -e "\${HOME}/.iterm2_shell_integration.zsh" && source "\${HOME}/.iterm2_shell_integration.zsh";fi']: exit code: 1

Hey @nickfan , thanks for reporting this. What is the base image you are using in your Dockerfile? Have you tried without any plugins passed as parameter? The error may be caused by one of the plugins....

commented

now i just workaround run cmd with root and copy settings to non root user dir and change owner to make it work:

# syntax = docker/dockerfile:experimental
ARG USER_NAME="www"
ARG USER_PASSWORD="123456"
#ARG ZSH_THEME="ys"
ARG ZSH_THEME="powerlevel10k"
ARG TERM="xterm-256color"
ARG DEBIAN_FRONTEND=noninteractive
ARG TZ=etc/UTC

FROM ubuntu:18.04

ARG DEBIAN_FRONTEND
ENV DEBIAN_FRONTEND=${DEBIAN_FRONTEND}
ARG TZ
ENV TZ=${TZ}
ARG USER_NAME
ARG USER_PASSWORD
ENV USER_NAME=${USER_NAME}
ENV USER_PASSWORD=${USER_PASSWORD}
ARG TERM
ENV TERM=${TERM}
ARG ZSH_THEME
ENV ZSH_THEME=${ZSH_THEME}

ENV HOMEPATH /home/${USER_NAME}
SHELL ["/bin/bash", "-c"]


RUN set -eux; \
  apt-get update; \
  apt-get install -y --no-install-recommends \
  sudo net-tools iputils-ping iproute2 telnet curl wget nano procps traceroute iperf3 gnupg-agent apt-transport-https ca-certificates software-properties-common openssh-client openssh-server ntp ntpdate \
  zsh autojump fonts-powerline xfonts-75dpi xfonts-base xfonts-encodings xfonts-utils && \
  chsh -s /bin/zsh root && \
  addgroup ${USER_NAME} && adduser --quiet --disabled-password --shell /bin/zsh --ingroup ${USER_NAME} --home /home/${USER_NAME} --gecos "User" ${USER_NAME} && \
  echo "${USER_NAME}:${USER_PASSWORD}" | chpasswd && usermod -aG sudo ${USER_NAME} && usermod -aG adm ${USER_NAME} && usermod -aG www-data ${USER_NAME} && \
  sed -i -E "s/^Defaults env_reset/Defaults env_reset, timestamp_timeout=-1/g" /etc/sudoers && \
  ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN wget -O ~/.p10k.zsh https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-lean.zsh && sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)" -- \
  -t powerlevel10k/powerlevel10k \
  -p git \
  -p ssh-agent \
  -p z \
  -p autojump \
  -p history \
  -p last-working-dir \
  -p docker \
  -p github \
  -p jsontools \
  -p node \
  -p npm \
  -p golang \
  -p tmux \
  -p tmuxinator \
  -p catimg \
  -p https://github.com/zsh-users/zsh-autosuggestions \
  -p https://github.com/zsh-users/zsh-completions \
  -p https://github.com/zsh-users/zsh-syntax-highlighting \
  -p https://github.com/zsh-users/zsh-history-substring-search \
  -a 'export ZSH_DISABLE_COMPFIX=true' \
  -a 'HIST_STAMPS="yyyy-mm-dd"' \
  -a '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' \
  -a 'export ZSH_TMUX_AUTOSTART=false' \
  -a 'export ZSH_TMUX_AUTOCONNECT=false' \
  -a 'zstyle :omz:plugins:ssh-agent agent-forwarding on'
RUN sed -i -E "/POWERLEVEL9K_/d" /root/.zshrc && \
  cp -af /root/.oh-my-zsh /home/${USER_NAME}/ && \
  cp -af /root/.zshrc /home/${USER_NAME}/ && sed -i 's/root/home\/${USER_NAME}/g' /home/${USER_NAME}/.zshrc && \
  cp -af /root/.p10k.zsh /home/${USER_NAME}/ && \
  chown -R ${USER_NAME}:${USER_NAME} /home/${USER_NAME}/.oh-my-zsh && \
  chown -R ${USER_NAME}:${USER_NAME} /home/${USER_NAME}/.zshrc && \
  chown -R ${USER_NAME}:${USER_NAME} /home/${USER_NAME}/.p10k.zsh

RUN rm -rf /var/lib/apt/lists/*

i want to just run the line with non root user and without error,how to get it done?

USER myusername
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)" -- \
  -t powerlevel10k/powerlevel10k \
  -p git \
  -p ssh-agent \
  -p z \
  -p autojump \
  -p history \
  -p last-working-dir \
  -p docker \
  -p github \
  -p jsontools \
  -p node \
  -p npm \
  -p golang \
  -p tmux \
  -p tmuxinator \
  -p catimg \
  -p https://github.com/zsh-users/zsh-autosuggestions \
  -p https://github.com/zsh-users/zsh-completions \
  -p https://github.com/zsh-users/zsh-syntax-highlighting \
  -p https://github.com/zsh-users/zsh-history-substring-search \
  -a 'export ZSH_DISABLE_COMPFIX=true' \
  -a 'HIST_STAMPS="yyyy-mm-dd"' \
  -a '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' \
  -a 'export ZSH_TMUX_AUTOSTART=false' \
  -a 'export ZSH_TMUX_AUTOCONNECT=false' \
  -a 'zstyle :omz:plugins:ssh-agent agent-forwarding on'

Same question here, I am also trying to set up zsh/omz with non-root user/group but no luck.

I can't reproduce this with the latest version, 1.1.3. This is the Dockerfile I used (based on the sample Dockerfile in the project:

FROM ubuntu:18.04

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
    && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
    && apt-get update \
    && apt-get install -y sudo wget \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME \
    #
    # Clean up
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*

USER $USERNAME

RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.3/zsh-in-docker.sh)" -- \
    -t https://github.com/denysdovhan/spaceship-prompt \
    -a 'SPACESHIP_PROMPT_ADD_NEWLINE="false"' \
    -a 'SPACESHIP_PROMPT_SEPARATE_LINE="false"' \
    -p git \
    -p https://github.com/zsh-users/zsh-autosuggestions \
    -p https://github.com/zsh-users/zsh-completions \
    -p https://github.com/zsh-users/zsh-history-substring-search \
    -p https://github.com/zsh-users/zsh-syntax-highlighting \
    -p 'history-substring-search' \
    -a 'bindkey "\$terminfo[kcuu1]" history-substring-search-up' \
    -a 'bindkey "\$terminfo[kcud1]" history-substring-search-down'

ENTRYPOINT [ "/bin/zsh" ]
CMD ["-l"]

and this is the result:

$ docker build .
[+] Building 28.9s (7/7) FINISHED                                                                                                                                                                  
 => [internal] load build definition from Dockerfile                                                                                                                                          0.0s
 => => transferring dockerfile: 1.44kB                                                                                                                                                        0.0s
 => [internal] load .dockerignore                                                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                               0.0s
 => [internal] load metadata for docker.io/library/ubuntu:18.04                                                                                                                               0.3s
 => [1/3] FROM docker.io/library/ubuntu:18.04@sha256:6fec50623d6d37b7f3c14c5b6fc36c73fd04aa8173d59d54dba00da0e7ac50ee                                                                         0.0s
 => CACHED [2/3] RUN groupadd --gid 1000 vscode     && useradd -s /bin/bash --uid 1000 --gid 1000 -m vscode     && apt-get update     && apt-get install -y sudo wget     && echo vscode ALL  0.0s
 => [3/3] RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.3/zsh-in-docker.sh)" --     -t https://github.com/denysdovhan/spaceship-prompt     -a 'SPACE  25.7s
 => exporting to image                                                                                                                                                                        2.8s 
 => => exporting layers                                                                                                                                                                       2.7s 
 => => writing image sha256:2af8f10a8044a735822a54ee419c37122d0fc13d77cdce839fadc71f96d455fd                                                                                                  0.0s 

$ docker run -it sha256:2af8f10a8044a735822a54ee419c37122d0fc13d77cdce839fadc71f96d455fd
vscode in /  …➜ 

Closing this now, but feel free to chime in if you still have any issues