I have a problem with docker container build on top of my dockerfile, indeed each time I use the command: docker compose up -d, the container created from that instantly exit with status code 2, and the command **docker compose logs ** give no output.
Here is the dockerfile:
FROM alpine:3.18.0
WORKDIR /app
ARG APP_USER=ftp FTP_USER_USERNAME=dieriba FTP_USER_PASSWORD=ftp VSFTPD_VERSION=3.0.5-r2 OPENSSL_VERSION=3.1.1-r1
RUN apk -U update && apk add --no-cache vsftpd=${VSFTPD_VERSION} \
openssl=${OPENSSL_VERSION} \
openrc
COPY conf/vsftpd.conf /etc/vsftpd.conf
COPY conf/vsftpd.conf /etc/vsftpd/vsftpd.conf
COPY conf/dtoure.42.conf .
RUN mkdir -p wordpress
RUN openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 \
-config ./dtoure.42.conf \
-keyout /etc/vsftpd/server.key -out /etc/vsftpd/server.crt
RUN chown ${APP_USER}:${APP_USER} /etc/vsftpd/server.key && \
chmod 755 /etc/vsftpd/server.key && \
chown ${APP_USER}:${APP_USER} /etc/vsftpd/server.crt && \
chmod 755 /etc/vsftpd/server.crt
RUN adduser -D ${FTP_USER_USERNAME} && echo -n "$FTP_USER_USERNAME:$FTP_USER_PASSWORD" | chpasswd
RUN echo ${FTP_USER_USERNAME} > /etc/vsftpd/user_list
RUN chown -R ${APP_USER}:${APP_USER} /etc/vsftpd && \
chmod -R 755 /etc/vsftpd && \
chown -R ${APP_USER}:${APP_USER} /etc/vsftpd.conf && \
chmod -R 755 /etc/vsftpd.conf && \
chown -R ${APP_USER}:${APP_USER} /var/lib/ftp && \
chmod -R 755 /var/lib/ftp && \
touch /var/log/vsftpd.log && \
chown ${APP_USER}:${APP_USER} /var/log/vsftpd.log && \
chmod 444 /var/log/vsftpd.log
EXPOSE 20 21
USER ${APP_USER}:${APP_USER}
CMD ["/usr/sbin/vsftpd", "-D", "/etc/vsftpd.conf"]
Here is the vsftpd conf file:
# Allow local users to log in
local_enable=YES
pam_service_name=ftp
# Allow write access for local users
write_enable=YES
# Set the umask for uploaded files
local_umask=022
# Enable passive mode
pasv_enable=YES
# Specify the range of passive ports
pasv_min_port=30000
pasv_max_port=30010
# Enable FTP over TLS/SSL (optional, but recommended)
ssl_enable=YES
rsa_cert_file=/etc/vsftpd/server.crt
rsa_private_key_file=/etc/vsftpd/server.key
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
require_ssl_reuse=NO
ssl_ciphers=HIGH
# Set the chroot jail for users (optional)
chroot_local_user=YES
# Allow users with chrooted access to write to their root directory
allow_writeable_chroot=YES
# Specify the FTP welcome message
ftpd_banner=Dieri FTP SERVER
# Limit the maximum number of clients
max_clients=10
max_per_ip=5
# Hide the FTP server's identity
hide_ids=YES
# Set the FTP root directory
local_root=/app/wordpress
# Allow symbolic links to be followed
follow_symlinks=YES
userlist_file=/etc/vsftpd/user_list
userlist_enable=YES
userlist_deny=NO
And here is the docker compose file:
version: '3'
services:
vsftpd:
build:
context: '.'
dockerfile: Dockerfile-vsftpd
image: vsftpd-image:v1
ports:
- 20:20
- 21:21
env_file : ../../../.env
networks:
wp-nginx-mariadb:
I found the error, It was because I was launching the app with a non root user, where vstfpd by default except root user to launch the app, you have to either add the directive
"run_as_launching_user=YES"or let root user launch the application.