---
title: 'How to connect to a Docker container via sFTP | Zomro'
description: 'Connecting to a Docker container via sFTP can be useful for developers who work with files inside the container. For example, if you are developing a web...'
image: 'https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677414931_4.png'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * How to connect to a Docker container via sFTP 



# How to connect to a Docker container via sFTP

26-02-2023

Connecting to a Docker container via sFTP can be useful for developers who work with files inside the container. For example, if you are developing a web application and want to upload files to the server, you can connect to the container via sFTP and upload files to the server from your development environment.  
Additionally, when connecting to a Docker container via sFTP, you can use various sFTP functions to manage files. 

##   
  
**Deploying a Docker container via sFTP.**

  
  
To connect to a Docker container via sFTP, you first need to create a container that will be running on a remote server. You can use the docker run command for this. For example, to run a container with nginx on port 2222 and install OpenSSH, you can use the following commands:  

    
    
    docker run -d -p 2222:22 --name nginx_latest nginx
    
    
    docker exec -it nginx_latest apt-get update
    
    
    docker exec -it nginx_latest apt-get install -y openssh-server

  
![How to connect to a Docker container via sFTP - 1](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677414931_4.png)  


These commands will create a new container named "nginx_latest" based on the Nginx image and install OpenSSH inside the container. 

  
  
**Set a password for the selected user.**  
  
Set a password for root (or any other user you want to connect with) by running the following command:
    
    
    docker exec -it nginx_latest passwd root

  
Enter the password twice.  


  
![How to connect to a Docker container via sFTP - 2](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677414919_33.png)

  * Edit the /etc/ssh/sshd_config file inside the container, replacing **PermitRootLogin without-password** with **PermitRootLogin yes**. To connect and edit it, use the following command:


    
    
    docker exec -it nginx_latest bash

  


Use your favorite editor. If it's not available, install it.

  
  
![How to connect to a Docker container via sFTP - 3](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677414927_66.png)

  * Restart the SSH server by running the command:


    
    
    /etc/init.d/ssh restart

  
![How to connect to a Docker container via sFTP - 4](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677415025_55.png)  


## **Connecting to a Docker container via IP using sFTP.**

  
  
  
To do this, you need to determine the IP address of the container and the port on which the SSH server is running. You can do this using the docker inspect command. For example, if the container is running on port 2222, you can use the following command to get the IP address:
    
    
    docker inspect --format '{{ .NetworkSettings.IPAddress }}' nginx_latest
    

  
![How to connect to a Docker container via sFTP - 5](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677414897_44.png)  
  


This command will return the IP address of the container. Then you can connect to the container via sFTP using the user credentials set inside the container. For example, using the sftp command:
    
    
    sftp root@172.17.0.4
    

  


Where root is the username set inside the container, and ip-address is the IP address of the container (172.17.0.4) obtained using the docker inspect command.

  
  
![How to connect to a Docker container via sFTP - 6](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677414823_6.png)  


## **Connecting with FileZilla.**

  1. In the "File" menu, select "Site Manager" (or use the hotkey "Ctrl+S").

  2. In the "Site Manager" window, click the "New Site" button and enter the name of your site.
  3. In the "Host", "Port", "Username", and "Password" fields, enter the corresponding values using the information from your Docker container. By default, the username is "root" and the port is "2222".
  4. In the "Protocol" dropdown, select "SFTP - SSH File Transfer Protocol".
  5. Click "Connect". If all settings are correct, you should be connected to your Docker container via sFTP using the sFTP client.



![How to connect to a Docker container via sFTP - 7](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677415617_7.png)  


Now you can connect to your Docker container via sFTP, transfer files, and perform other file operations on the remote server.

​​​​​​​We also suggest you other useful articles:

  * [How to copy data from a host to Docker and from Docker to a host](https://zomro.com/blog/faq/284-kak-skopirovat-dannye-s-hosta-v-docker-i-iz-docker-na-host)
  * [List of important commands for working with Docker-compose](https://zomro.com/blog/faq/304-spisok-vazhnyh-komand-dlja-raboty-s-docker-compose)
  * [How to install Redis in Docker and Docker Compose](https://zomro.com/blog/faq/301-kak-ustanovit-redis-v-docker)



Similar articles:

[cPanel File Manager](https://zomro.com/blog/faq/177-menedzher-fajlov-cpanel) [Applications for accessing FX VPS and more](https://zomro.com/blog/faq/181-prilozhenija-dlja-vhoda-na-fx-vps-i-ne-tolko) [Installing MetaTrader 4/5 on a Zomro server](https://zomro.com/blog/faq/648-installing-metatrader-45-on-the-zomro-server) [Vim text editor](https://zomro.com/blog/faq/204-redaktor-vim) [Installing a game server for Terraria - TShock on Centos 7](https://zomro.com/blog/faq/250-ustanovka-igrovogo-servera-dlja-teraria-tshock-na-centos-7)

[ GPU server from €174.80/mon ](/dedicated-servers/type=gpu)
