-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal-Dockerfile
51 lines (39 loc) · 1.57 KB
/
local-Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
FROM ubuntu:24.04
# Set environment variables to avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
# Install required packages
RUN apt-get update && apt-get install -y \
openssh-server \
python3.12 \
python3-pip \
ansible \
sshpass \
sudo \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Configure SSH server
RUN mkdir /var/run/sshd
# Store passwords in Base64 and decode during build
# admin321 (base64)
ENV ROOT_PASSWORD_BASE64="YWRtaW4zMjE="
# random321 (base64)
ENV ANSUSER_PASSWORD_BASE64="cmFuZG9tMzIx"
RUN echo "root:$(echo $ROOT_PASSWORD_BASE64 | base64 -d)" | chpasswd && \
useradd -m -s /bin/bash ansuser && \
echo "ansuser:$(echo $ANSUSER_PASSWORD_BASE64 | base64 -d)" | chpasswd
# Enable SSH login for root
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# Add "ansuser" to the sudo group and grant passwordless sudo
RUN usermod -aG sudo ansuser && \
echo "ansuser ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ansuser && \
chmod 0440 /etc/sudoers.d/ansuser
# Ensure the SSH directory exists and set correct permissions
RUN mkdir -p /home/ansuser/.ssh && chmod 700 /home/ansuser/.ssh
# Add the SSH public key to ansuser's authorized_keys
COPY id_ed25519_vettabase_ansible_mariadb.pub /home/ansuser/.ssh/authorized_keys
# Set correct permissions for the SSH key
RUN chmod 600 /home/ansuser/.ssh/authorized_keys && \
chown -R ansuser:ansuser /home/ansuser/.ssh
# Expose SSH, MySQL, and Galera ports
EXPOSE 22 3306 4567 4568 4444
# Start SSH server by default
CMD ["/usr/sbin/sshd", "-D"]