You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过FTP连接Microsoft SQL Server Docker容器?

Hey there! Let's break down your problem step by step since you're new to Docker and working with the SQL Server image.

1. Fixing the "same container name" issue

You can't run a new container with the same name (sql1) as an existing one—Docker prevents this to avoid conflicts. You have two straightforward options here:

  • Option 1: Remove the existing container (if you don't need it anymore)
    First stop the running container:

    sudo docker stop sql1
    

    Then delete it:

    sudo docker rm sql1
    

    Now you can run your new container command with the -p 21:21 port mapping included.

  • Option 2: Rename the existing container (if you want to keep it for reference)
    Rename the old container to something like sql1-old:

    sudo docker rename sql1 sql1-old
    

    Now you can safely launch your new sql1 container with the FTP port mapped.

2. Adding FTP service to your SQL Server container

The official SQL Server Docker image doesn't include an FTP server by default. You have two reliable ways to add this functionality:

This method creates a reusable image with both SQL Server and FTP pre-configured—your settings will persist across container restarts.

  1. Create a file named Dockerfile with the following content:

    FROM mcr.microsoft.com/mssql/server:2019-latest
    
    USER root
    
    # Install vsftpd (a popular, lightweight FTP server)
    RUN apt-get update && apt-get install -y vsftpd \
        && rm -rf /var/lib/apt/lists/*
    
    # Configure vsftpd for secure, local user access
    RUN echo "listen=YES" >> /etc/vsftpd.conf \
        && echo "listen_ipv6=NO" >> /etc/vsftpd.conf \
        && echo "anonymous_enable=NO" >> /etc/vsftpd.conf \
        && echo "local_enable=YES" >> /etc/vsftpd.conf \
        && echo "write_enable=YES" >> /etc/vsftpd.conf \
        && echo "local_umask=022" >> /etc/vsftpd.conf \
        && echo "dirmessage_enable=YES" >> /etc/vsftpd.conf \
        && echo "use_localtime=YES" >> /etc/vsftpd.conf \
        && echo "xferlog_enable=YES" >> /etc/vsftpd.conf \
        && echo "connect_from_port_20=YES" >> /etc/vsftpd.conf \
        && echo "chroot_local_user=YES" >> /etc/vsftpd.conf \
        && echo "allow_writeable_chroot=YES" >> /etc/vsftpd.conf \
        && echo "pasv_min_port=30000" >> /etc/vsftpd.conf \
        && echo "pasv_max_port=30010" >> /etc/vsftpd.conf
    
    # Create a dedicated FTP user (replace the password with your own strong one)
    RUN useradd -m ftpuser \
        && echo "ftpuser:<YourFtpStrong@Passw0rd>" | chpasswd
    
    # Switch back to the default mssql user (required for SQL Server to run correctly)
    USER mssql
    
    # Start both SQL Server and vsftpd when the container launches
    CMD /bin/bash -c "/opt/mssql/bin/sqlservr & /usr/sbin/vsftpd & wait"
    
  2. Build your custom image:

    sudo docker build -t mssql-with-ftp:2019-latest .
    
  3. Run the new container with all required ports (including FTP passive mode ports):

    sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong@Passw0rd>" \
    -p 1433:1433 -p 21:21 -p 30000-30010:30000-30010 \
    --name sql1 --hostname sql1 \
    -d mssql-with-ftp:2019-latest
    

Option B: Install FTP temporarily in the existing container (for testing only)

This works for quick tests, but all changes will be lost when the container restarts—Docker containers are ephemeral by default.

  1. Access the container as root (since you need admin rights to install software):

    sudo docker exec -it -u root sql1 bash
    
  2. Install vsftpd:

    apt-get update && apt-get install -y vsftpd
    
  3. Configure vsftpd using the same settings as in the Dockerfile above (edit /etc/vsftpd.conf with a text editor like nano).

  4. Create an FTP user and start the service:

    useradd -m ftpuser
    echo "ftpuser:<YourFtpStrong@Passw0rd>" | chpasswd
    /usr/sbin/vsftpd
    
3. FTP Connection Notes
  • Use passive mode: Most FTP clients use passive mode by default. Make sure you've mapped the passive port range (30000-30010) and opened those ports on your server's firewall (e.g., with ufw: sudo ufw allow 21/tcp && sudo ufw allow 30000:30010/tcp).
  • Use the dedicated FTP user: Don't try to connect with the sa account—that's only for SQL Server authentication. Use the ftpuser you created instead.
  • Enforce strong passwords: Both your SA_PASSWORD and FTP user password must meet complexity requirements (mix of uppercase, lowercase, numbers, and special symbols) to avoid container startup failures or security risks.

内容的提问来源于stack exchange,提问作者Laurent K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 13:54:06