docker install sftp through dockerfile

Dockerfile

FROM atmoz/sftp

VOLUME /home/mocha/order/data/attachment/

EXPOSE 22

To install SFTP using a Dockerfile, you can follow these steps:

  1. Create a directory and enter it:
mkdir sftp
cd sftp
  1. Create a Dockerfile:
touch Dockerfile
  1. 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.

  1. Build the Docker image:
docker build -t my-sftp .
  1. 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.

Guess you like

Origin blog.csdn.net/qq_41848006/article/details/131331667