这是我的Dockerfile,用于在8031端口上通过SSH进行简单访问
FROM alpine:latest
RUN apk add --no-cache php8
php8-common
php8-fpm
php8-pdo
php8-opcache
php8-zip
php8-phar
php8-iconv
php8-cli
php8-curl
php8-openssl
php8-mbstring
php8-tokenizer
php8-fileinfo
php8-json
php8-xml
php8-xmlwriter
php8-xmlreader
php8-simplexml
php8-dom
php8-pdo_mysql
php8-pdo_sqlite
php8-tokenizer
php8-pecl-redis
php8-pdo_pgsql
php8-gd
RUN apk add --update --no-cache openssh
RUN apk add sudo
RUN echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
RUN echo 'Port 8031' >> /etc/ssh/sshd_config
RUN adduser -h /home/userdev -s /bin/sh -D userdev
RUN echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel
RUN adduser userdev wheel
RUN echo -n 'userdev:mypassword' | chpasswd
ENTRYPOINT ["/entrypoint.sh"]
RUN apk --update --no-cache upgrade
&& apk add bash
&& apk add nano
&& apk add nodejs npm
&& apk add gmp gmp-dev
&& apk add git htop
&& apk add mc nano
&& apk add acl screen
RUN mkdir -pv /var/www/html
RUN setfacl -R -m u:userdev:rwX /var/www/html
COPY .screenrc /home/userdev/
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
EXPOSE 8031
COPY entrypoint.sh /
入口点.sh
#!/bin/bash
ssh-keygen -A
exec /usr/sbin/sshd -D -e "$@"
docker compose.yml
name: docker-openssh-server
services:
openssh:
image: alpine-sshd-final:latest
ports:
- "8031:8031"
network_mode: "host"
volumes:
- /var/www/html:/var/www/html
- ./sshd_config:/etc/ssh/sshd_config
networks:
default:
name: docker-openssh-server_default
当我连接到SSH守护进程时,一切都正常工作——我可以在没有密码的情况下运行sudo -i
。
但当我运行docker exec -it -u userdev:userdev container_name /bin/bash
时,sudo会询问密码吗?
为什么会发生这种情况?在第二种情况下,是否也可以使其无密码?
解决方案非常简单:我必须执行docker exec -it -u userdev:wheel container_name /bin/bash
,一切正常!如张贴在这里