Dockerfile
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
# setting account, password
RUN echo 'root:supwd' |chpasswd
RUN sed -ri 's/^#?PermitRootLogin\\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN mkdir /root/.ssh
RUN apt-get clean && \\
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Build
# 建立 image
$ docker build -t ubuntu-18.04-ssh .
# 啟動 container
$ docker run -d -p 10022:22 ubuntu-18.04-ssh
# 內部進入 container 方法
$ ssh [email protected] -p10022
# 外部進入 container 方法,假設該主機 IP 為 192.168.1.103
$ ssh [email protected] -p10022
Dockerfile
FROM ubuntu:18.04
RUN apt update && apt install -y git zsh curl vim
RUN sh -c "$(curl -fsSL <https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh>)"
RUN git clone <https://github.com/zsh-users/zsh-autosuggestions> ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
RUN git clone <https://github.com/zsh-users/zsh-syntax-highlighting> ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
RUN sed -i "s/^plugins=.*/# &/" ~/.zshrc && sed -i '/^# plugins=.*/ a plugins=(git zsh-autosuggestions zsh-syntax-highlighting)' ~/.zshrc
RUN git clone --depth=1 <https://github.com/romkatv/powerlevel10k.git> ~/.oh-my-zsh/custom/themes/powerlevel10k
RUN sed -i "s/^ZSH_THEME=.*/# &/" ~/.zshrc && sed -i '/^# ZSH_THEME=.*/ a ZSH_THEME=\\"powerlevel10k\\/powerlevel10k\\"' ~/.zshrc
RUN chsh -s $(which zsh)
CMD zsh
Build
# 建立 image
$ docker build -t ubuntu-1804-zsh .
# 啟動 container
$ docker run -it ubuntu-1804-zsh
# 設定 powerlevel10k 主題偏好設定
Dockerfile
FROM ubuntu
RUN apt update
# 安裝 sudo 指令
RUN apt install -y sudo
# 新增使用者(需要使用 useradd 而不是互動式的 adduser)
RUN useradd -ms /bin/bash newuser
# 修改該使用者的密碼
RUN echo 'newuser:userpwd' | chpasswd
# 將該使用者加入 sudo 群組
RUN adduser newuser sudo
# 設定 Container 啟動時的預設 user
USER newuser
# 設定預設工作目錄
WORKDIR /home/newuser
CMD bash
Build
docker build -t newuser .
docker run -it newuser