Dockerfile
FROM atmoz/sftp
VOLUME /home/mocha/order/data/attachment/
EXPOSE 22
To install SFTP using a Dockerfile, you can follow these steps:
- Create a directory and enter it:
mkdir sftp
cd sftp
- Create a Dockerfile:
touch Dockerfile
- Add the following content to the Dockerfile:
FROM atmoz/sftp
RUN useradd user && echo 'user:password' | chpasswd
RUN mkdir /home/user/data && chown user:user /home/user/data
The above Dockerfile is built based on the atmoz/sftp image, which has OpenSSH and SFTP servers installed.
Next, we create a username and password for the new user and create a data directory.
- Build the Docker image:
docker build -t my-sftp .
- Run the Docker container:
docker run -p 2222:22 --name my-sftp -d my-sftp
This will start a container named my-sftp and map the container's port 22 to the host's port 2222. Now you can use sftp and ssh clients to connect to the container and upload/download files. For example:
sftp user@localhost -p 2222
Enter your username and password and you will enter the SFTP shell.