forked from Samsung/tizen-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Docker
Ryan Choi edited this page Aug 17, 2023
·
3 revisions
Note
# docker build --build-arg USER=ubuntu --build-arg PASSWORD=ubuntu -t ryanc/ubuntu .
# docker run -it --rm -p 2222:22 --user ryanc
# https://code-maven.com/docker-as-regular-user-and-as-root
FROM ubuntu:latest
# Use bash in this dockerfile
SHELL ["/bin/bash", "-c"]
ARG DEBIAN_FRONTEND=noninteractive
ARG USER=${USER:-ubuntu}
ARG PASSWORD=${PASSWORD:-ubuntu}
ENV TZ=Asia/Seoul
ENV USER=${USER}
ENV PASSWORD=${PASSWORD}
RUN apt update && apt install -y sudo less zsh vim git openssh-server curl net-tools &&\
apt -y autoremove && \
rm -fr /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN useradd -u 1000 -m -s /usr/bin/bash $USER && \
usermod -aG sudo $USER && \
touch /etc/sudoers && \
echo "$USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
echo "$USER:$PASSWORD" | chpasswd && \
mkdir -p /run/sshd && \
ssh-keygen -A
RUN sed -i 's/#PermitRootLogin/PermitRootLogin no #/g' /etc/ssh/sshd_config && \
sed -i 's/#PasswordAuthentication/PasswordAuthentication yes #/g' /etc/ssh/sshd_config && \
sed -i 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
# docker compose up -d --build
version: '3.8'
services:
ubuntu-sshd:
container_name: ubuntu-sshd
hostname: ubuntu # hostname seen inside the docker
build:
context: .
dockerfile: Dockerfile
args:
- USER=ryanc
- PASSWORD=ubuntu
image: ryanc/ubuntu-sshd:latest
ports:
- "2222:22"