Skip to content

Instantly share code, notes, and snippets.

@62mkv
Last active April 10, 2021 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 62mkv/ca74f50ea8f77bcc863aaec17cb3e93a to your computer and use it in GitHub Desktop.
Save 62mkv/ca74f50ea8f77bcc863aaec17cb3e93a to your computer and use it in GitHub Desktop.
Hosting FTP in Docker with Docker Desktop under Windows 10

Sneak on docker containers' traffic:

docker run --rm --net=host -v $PWD/tcpdump:/tcpdump kaazing/tcpdump

This will save tcpdump.pcap to tcpdump folder under current directory. That file can be opened with WireShark (sometimes it fails to open the file - check if any concurrent instances of tcpdump container are still running)

Run vsftpd container with mapped volume:

docker run --rm -it -p 21:21 -p 4559-4564:4559-4564 -v c:\temp:/srv -e FTP_USER=ftp -e FTP_PASSWORD=ftp docker.io/panubo/vsftpd:latest

This will map a c:\temp folder as /srv folder inside the container, i.e. this is the root of folder that is hosted over FTP

@Testcontainers
@SpringBootTest(classes = [FtpConfiguration::class])
@Disabled("some Permissions issue under Docker Desktop/Windows 10; also, mapping fixed ports could not possibly work in all situations")
class FtpIntTest {
@Autowired
lateinit var ftpFilePublisher: FtpFilePublisher
companion object {
val logger = LoggerFactory.getLogger(FtpIntTest::class.java)
@Container
private val ftpContainer = GenericContainer<GenericContainer<*>>(DockerImageName.parse("panubo/vsftpd:latest"))
.withEnv("FTP_USER", "guest")
.withEnv("FTP_PASSWORD", "guest")
.withFileSystemBind("C:\\temp", "/srv", BindMode.READ_WRITE)
.withCreateContainerCmdModifier {
it.withHostConfig(
HostConfig.newHostConfig()
.withPortBindings(Arrays.asList(
PortBinding.parse("21:21"),
PortBinding.parse("4559:4559"),
PortBinding.parse("4560:4560"),
PortBinding.parse("4561:4561"),
PortBinding.parse("4562:4562"),
PortBinding.parse("4563:4563"),
PortBinding.parse("4564:4564"),
))
)
}
val logConsumer = Slf4jLogConsumer(logger)
@DynamicPropertySource
@JvmStatic
fun registerDynamicProperties(registry: DynamicPropertyRegistry) {
registry.add("export.ftp.hostname", ftpContainer::getContainerIpAddress)
registry.add("export.ftp.port") { ftpContainer.getMappedPort(21) }
registry.add("export.ftp.username") { "guest" }
registry.add("export.ftp.password") { "guest" }
logger.info("hostname {} port {}", ftpContainer.getContainerIpAddress(), ftpContainer.getMappedPort(21))
ftpContainer.followOutput(logConsumer)
}
}
@Test
fun `can publish the file`() {
val inputStream = ByteArrayInputStream("my-file".toByteArray())
ftpFilePublisher.publishFile("","test", inputStream)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment