Running telnet.exe inside Windows Containers: A Step-by-Step Guide

Abstract: Enables telnet.exe in Windows Server LTSC 2022 containers by using Enable-WindowsOptionalFeature instead of deprecated Add-WindowsFeature cmdlets.

Created: 2026-10-07 by
To run telnet.exe inside Windows containers, you must enable the Telnet-Client feature during the image build process using PowerShell cmdlets rather than legacy package managers. This approach ensures compatibility with modern base images like Windows Server LTSC 2022 and Nano Server, which have different feature management capabilities compared to older Server Core versions. By adding a specific RUN instruction in your Dockerfile, you can seamlessly integrate this utility for network diagnostics without increasing the container footprint unnecessarily.

Understanding Feature Management in Modern Windows Containers

Historically, enabling features in Windows Server containers involved using the Add-WindowsFeature cmdlet or the dism command-line tool. However, Microsoft has deprecated these methods for newer operating system versions, particularly Windows Server 2019 LTSC and 2022 LTSC. The primary reason for this shift is that these newer OS versions utilize a more modular component store managed through PowerShell. If you attempt to use Add-WindowsFeature on an LTSC-based image, the build will fail because the cmdlet simply does not exist in the default environment. For developers working with Windows containers, it is crucial to recognize that "Nano Server" and "Windows Server Core" are no longer the only distinct choices; we now have LTSC variants that behave differently. While some older guides suggest using Install-WindowsFeature, this is technically incorrect for the current generation of Windows Server containers. Instead, the supported method relies entirely on the Enable-WindowsOptionalFeature cmdlet available in PowerShell. This change requires updating your Dockerfiles to reflect the correct syntax, ensuring that your builds remain stable across different host environments.

The Correct PowerShell Approach

The recommended way to add telnet support is by leveraging the Enable-WindowsOptionalFeature command. This cmdlet interacts directly with the Windows Component Store (WinSxS) to install optional features. When constructing your Dockerfile, you should invoke PowerShell within a RUN instruction to execute this command. It is important to include the -Online parameter, which targets the running operating system instance within the container, and the -NoRestart parameter to prevent unnecessary reboot cycles during the build phase. This results in a cleaner and faster build process, as the container does not need to restart between layer creation.

Constructing the Dockerfile

Creating a custom image that includes telnet.exe is straightforward once you know the correct syntax. You start with a standard Windows base image, such as mcr.microsoft.com/windows/servercore:ltsc2022. From there, you add a step to enable the client feature. Below is a complete example of a minimal Dockerfile that successfully installs the telnet client.
FROM mcr.microsoft.com/windows/servercore:ltsc2022

# Enable the Telnet Client feature
RUN powershell -Command \
    Enable-WindowsOptionalFeature -Online -FeatureName TelnetClient -NoRestart

# Optional: Verify installation
RUN telnet localhost 80

CMD ["cmd"]
In this example, the FROM statement pulls the latest LTSC 2022 server core image. The RUN command executes PowerShell to enable the TelnetClient feature. Note that the feature name is case-sensitive and must match exactly what is registered in the Windows Component Store. After the build completes, the resulting image will contain telnet.exe in its system path, allowing you to use it immediately upon container startup.

Common Pitfalls and Troubleshooting

Many users encounter errors when trying to adapt old scripts to new container bases. One common mistake is assuming that all Windows container images support the same set of PowerShell modules. For instance, if you are using a very minimal base image, you might find that PowerShell itself is not fully featured. However, standard Server Core images include the necessary infrastructure for Enable-WindowsOptionalFeature. If you receive an error stating that the feature cannot be found, double-check the spelling of TelnetClient. Another frequent issue arises from network policies; while telnet can connect to ports, firewalls on the host machine or within the container network configuration may block outbound connections. Always test connectivity using simple tools like Test-NetConnection in PowerShell before relying on telnet for complex debugging.

Alternative Diagnostic Tools

While telnet is useful for basic port testing, modern Windows containers often benefit from more robust networking diagnostic tools. PowerShell provides Test-NetConnection, which offers detailed output about TCP handshake success, latency, and route information. Additionally, tools like curl are frequently pre-installed or easily added to images for HTTP-specific testing. If you are building a production-grade container, consider whether telnet is truly necessary or if built-in PowerShell cmdlets can achieve the same diagnostic goals without adding extra binaries to your image. This aligns with best practices for keeping container images lean and secure. For more advanced scenarios involving graphical interfaces or complex application deployments, you might also want to explore how other applications are handled in native kernel-based environments, as discussed in our guide on Running GUI Applications in Native Kernel-based Windows Containers. Understanding the broader context of application deployment helps in making informed decisions about which utilities to include in your final container image.

Frequently Asked Questions

Does Nano Server support Enable-WindowsOptionalFeature?

No, Nano Server does not include the full PowerShell module required for Enable-WindowsOptionalFeature. This cmdlet is primarily available in Server Core and Desktop Experience images. If you are using Nano Server, you generally cannot install telnet or similar optional features because they are not part of the minimal component set.

Why did my previous Dockerfile fail with Add-WindowsFeature?

The Add-WindowsFeature cmdlet was removed in Windows Server 2016 and later versions. If you are using LTSC 2022 or 2019 images, this cmdlet no longer exists. You must switch to Enable-WindowsOptionalFeature to successfully install features during the build process.

Can I install telnet at runtime instead of build time?

Technically yes, but it is highly discouraged. Installing features at runtime requires the container to have write access to the system drive and may trigger restarts. Building the feature into the image layer ensures consistency and allows you to verify the installation during the CI/CD pipeline.

Is telnet secure to use in production containers?

Telnet transmits data in plaintext, including credentials, making it insecure for production environments. It is recommended only for internal debugging or isolated testing networks. For secure remote access or file transfer, use SSH or SFTP equivalents instead.

What if I need other optional features besides telnet?

You can install multiple features by chaining commands or listing them in a single Enable-WindowsOptionalFeature call. For example, you can add PowershellISE or NetFx4-AdvShr using the same syntax. Always ensure the feature name matches the official Windows documentation.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More