Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

You normally do not SSH directly into an ordinary Docker container. SSH to the VPS that runs Docker, identify the running container, and start a shell inside it with docker exec:

ssh user@VPS_HOST
docker ps
docker exec -it CONTAINER_NAME sh

Use bash instead of sh only when the image contains Bash. The container must be running, and your VPS account must be allowed to use the Docker daemon.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What “SSH into a Docker container” actually means

For most application containers, the supported administration path has two separate stages:

  1. SSH authentication takes place on the VPS host, using the account and key supplied by your VPS administrator or provider.
  2. Docker process access takes place on that host, where the Docker CLI asks the daemon to start a new process inside a running container.

The shell you see after docker exec -it is therefore not a second SSH session. It is a process created inside the container by the Docker daemon. The normal sequence is:

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
ssh user@VPS_HOST
docker ps
docker exec -it CONTAINER_NAME sh

This model keeps host authentication, Docker permissions, and container administration in one controlled path. It also works with minimal images that do not run an SSH server at all.

Before you connect: requirements and assumptions

  • An SSH-reachable VPS hostname or IP address.
  • A valid host account and the corresponding private key, or another authentication method approved by the administrator.
  • The Docker CLI installed on the VPS, and a daemon running there.
  • Permission for your host account to communicate with the Docker socket.
  • A target container that is currently running if you plan to use docker exec.
  • An executable shell or command that exists in the target image. Most images include sh; not all include bash.

Container names and IDs are different from image names. An image is the packaged template; a container is the running (or stopped) instance created from that image. Pass the container name or ID to docker exec.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step-by-step: open a shell in a running container

1. SSH to the VPS host

Run this from your workstation, replacing the placeholders with the account and address assigned to you:

ssh user@VPS_HOST

If your key is not the default key, specify it with the SSH client’s normal option:

ssh -i /path/to/private_key user@VPS_HOST

After authentication, check that your prompt is on the VPS rather than on your local computer. Every Docker command in the following steps must run on that host unless you deliberately choose the remote Docker method described later.

2. List running containers

Display the containers that are currently running:

docker ps

The output includes a container ID, image, command, creation time, status, published ports, and a human-readable name. Use the value in the NAMES column for subsequent commands. If you need a compact list of names and IDs, you can use:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker ps --format '{{.ID}}  {{.Names}}  {{.Status}}'

When the expected application is absent, include stopped containers:

docker ps --all

A stopped container cannot accept an interactive shell, but its entry in this list lets you verify the exact name and see why it may have exited.

3. Start the container when it is stopped

If docker ps --all shows the target with an exited or created status, start that existing container:

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
docker start CONTAINER_NAME

You may use the container ID instead of its name. Confirm that it is running before attempting an exec session:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker ps

docker start changes the container’s lifecycle state; it does not open a terminal. The next command is still required to create a shell process.

4. Open an interactive shell with sh

Use the POSIX shell first because it is present in many small production images:

docker exec -it CONTAINER_NAME sh

The -i option keeps standard input open, and -t allocates a terminal. Together they provide a normal interactive prompt. To use an ID, substitute the ID directly:

docker exec -it CONTAINER_ID sh

Your prompt and available commands depend entirely on the image. A deliberately minimal image may contain only a shell and a few application utilities.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. Use Bash only if the image provides it

Some distributions and development images include Bash with additional conveniences. Try it when you know it is installed:

docker exec -it CONTAINER_NAME bash

If Docker reports that the executable cannot be found, return to sh or inspect the image for another available shell. Do not install an SSH server merely to obtain a shell; adding packages to a running container is usually lost when the container is replaced and creates another service to secure.

6. Run a one-off command without opening a shell

docker exec can start any executable in the running container. Omit -it for non-interactive checks:

docker exec CONTAINER_NAME ls /app
docker exec CONTAINER_NAME printenv
docker exec CONTAINER_NAME cat /etc/os-release

The command’s exit status is returned to your host terminal, which makes this form useful in scripts and health checks. Add -u USER when the command must run as a specific user and that user exists in the image:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
docker exec -u USER CONTAINER_NAME COMMAND

Use the image’s own paths and utilities; a host path such as /var/log is not automatically the same directory inside the container.

7. Leave the container shell

Type:

exit

This terminates the shell process that docker exec started. It does not intentionally stop the container’s primary application process. You will return to the VPS host prompt, where you can run other Docker commands or type exit again to close the SSH connection.

docker exec versus docker attach

Choose the command based on which process you need to observe or control. They are not interchangeable.

Aspect docker exec docker attach
Process targeted Starts a new process, commonly a shell, inside the running container. Connects your terminal to the container’s existing entrypoint process, normally PID 1.
Typical purpose Inspect files, run diagnostics, execute maintenance commands, or obtain an administrator shell. View or interact with the main process’s standard input, output, and error streams.
Effect of leaving exit ends the new shell or command; the main process normally continues. Detaching leaves the main process running, but signals sent through the attached terminal can affect it.
Image requirement Requires the requested executable, such as sh or bash, in the image. Does not require a shell because it connects to the existing entrypoint.
Risk of accidental interruption Generally limited to the command you launched. Higher: Ctrl-C may send a signal to the foreground process and can stop or interrupt it.

Use docker attach CONTAINER_NAME only when you deliberately need the main process’s terminal. Docker’s documented detach sequence for an interactive TTY is Ctrl-P followed by Ctrl-Q. A slow or high-volume application should usually be inspected with logs instead:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker logs CONTAINER_NAME

Attaching is not a substitute for a diagnostic shell, and pressing Ctrl-C while attached can have a materially different result from pressing it inside an exec shell.

Run Docker commands from your workstation with an SSH context

You can administer a remote Docker daemon without first opening an interactive host shell. Docker supports an SSH transport for this purpose. The remote SSH account still needs permission to access the Docker socket.

Create and select a reusable context

docker context create --docker host=ssh://docker-user@vps.example.com vps
docker context use vps
docker ps

Once the context is selected, ordinary Docker commands use the VPS daemon. To return to your local daemon, select your previous context with docker context use and its name.

Use a temporary DOCKER_HOST setting

For a single shell session, point the CLI at the SSH endpoint with an environment variable:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
export DOCKER_HOST=ssh://docker-user@vps.example.com
docker ps
docker exec -it CONTAINER_NAME sh

This approach still creates the shell inside the remote container; only the Docker client remains on your workstation.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Reuse SSH connections when appropriate

Docker’s SSH guidance documents OpenSSH connection multiplexing options such as:

ControlMaster auto
ControlPath ~/.ssh/control-%C
ControlPersist yes

These settings can reduce repeated authentication overhead when many Docker commands are sent over the same VPS connection. Apply them in the SSH configuration for the relevant host and account, and follow your organization’s key-management policy.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not replace the SSH transport with an unauthenticated Docker TCP socket exposed to the internet. The SSH endpoint preserves SSH authentication and encryption while avoiding a publicly reachable daemon port.

Why ordinary containers should not run their own SSH server

Docker’s security guidance describes SSH access as typically being managed by a single server on the Docker host. The CIS Docker Benchmark 1.11.0 recommendation 5.6 says an SSH server should not be running within the container. The host-SSH-plus-docker exec model follows that recommendation for ordinary application containers.

Installing sshd in every container creates another set of keys, passwords, users, configuration files, ports, logs, patches, and firewall rules. It also complicates the distinction between the host’s administrative boundary and the application’s runtime. Containers are commonly replaced during deployment, so hand-editing an SSH configuration inside one is not a durable operations process.

A container that is intentionally designed to provide an SSH service is a different architecture. For that application, publish the SSH port deliberately, restrict it at the firewall, use key authentication, patch the image, monitor authentication events, and include the container’s SSH configuration in the application’s threat model. Those steps are separate from gaining administrative access to a normal web, worker, database, or API container.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Docker permissions are host-level privileges

A successful SSH login does not automatically grant Docker access. The Docker CLI communicates with the daemon through its socket, and the daemon can create containers, mount host paths, change privileges, and otherwise control the host. Docker warns that access to the daemon is effectively root-equivalent on the machine.

If you receive a Docker socket permission error:

  • Confirm that you are using the intended VPS account, not a restricted deployment account.
  • Ask the administrator to grant the narrowest approved Docker access, or to perform the operation for you.
  • Do not copy a privileged daemon key to an untrusted workstation.
  • Do not work around the error by exposing an unauthenticated TCP daemon.

Membership in a host group that can access the Docker socket may be operationally convenient, but it remains a powerful privilege. Treat the account, private key, and any Docker context configuration as sensitive host-administration credentials.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

Permission denied while trying to connect to the Docker daemon socket

The host account cannot access the Docker socket, or the daemon is unavailable. Verify that the Docker service is running according to your VPS’s administration policy, then use an authorized account or request a narrowly controlled permission change. Avoid broadening network exposure to fix a local authorization problem.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

No such container

List all containers and copy the exact name or ID:

docker ps --all

Check spelling, punctuation, and whether an orchestration tool generated a different name. Supplying an image name instead of a container identifier produces this error.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

executable file not found for bash or sh

The requested program is absent or is located under a different path. Try the other common shell, inspect the image documentation, or run an executable that the image is known to contain. A minimal or distroless image may intentionally have no shell at all; in that case use one-off commands that exist, inspect logs, or create a diagnostic image rather than assuming an interactive shell is available.

The container exits immediately

docker exec requires a running container. Inspect its status and recent output:

docker ps --all
docker logs CONTAINER_NAME

Find and correct the application or configuration error that causes the main process to exit, then start the container again. Starting it repeatedly without examining the logs does not provide a usable exec target.

You need the application’s main terminal

Use:

docker attach CONTAINER_NAME

Remember that this connects to PID 1, not a new shell. Use the documented Ctrl-P, Ctrl-Q sequence to detach from an interactive TTY, and be cautious with Ctrl-C because it can signal the foreground process.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You want to administer the VPS daemon from a laptop

Use a Docker SSH context or a temporary DOCKER_HOST=ssh://... value. Confirm that the remote SSH user can access the Docker socket, and keep the daemon off unauthenticated public TCP endpoints.

Practical administration patterns

Inspect a web container’s application directory

ssh user@VPS_HOST
docker ps
docker exec web ls /app

This launches ls and returns to the host prompt without opening a persistent shell.

Check environment values without an interactive session

docker exec web printenv

Remember that environment output can contain credentials or tokens. Treat the terminal, shell history, CI logs, and copied output as sensitive.

Open a shell for several related checks

docker exec -it web sh
# run the required checks inside the container
exit

When the image has Bash:

docker exec -it web bash

Use the least-privileged container user that can complete the task where possible; a root shell inside a container still deserves caution because container capabilities, mounts, and daemon permissions determine the real impact.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Command reference

Goal Command Important condition
Connect to the host ssh user@VPS_HOST The account and key must be authorized on the VPS.
List running containers docker ps Shows only containers currently running.
List all containers docker ps --all Use when the target may be stopped or renamed.
Start an existing container docker start CONTAINER_NAME Does not open a shell.
Open a POSIX shell docker exec -it CONTAINER_NAME sh The container must be running and contain sh.
Open Bash docker exec -it CONTAINER_NAME bash Bash must be installed in the image.
Run one command docker exec CONTAINER_NAME COMMAND COMMAND must exist inside the container.
Read application output docker logs CONTAINER_NAME Use instead of attaching for high-volume output.
Connect to PID 1 docker attach CONTAINER_NAME Signals and detach behavior affect the main process.
Use a remote daemon over SSH export DOCKER_HOST=ssh://docker-user@vps.example.com The remote user needs Docker socket access.

Choosing the right access method

  • Need a maintenance shell: SSH to the VPS, then use docker exec -it ... sh.
  • Need a single diagnostic result: use non-interactive docker exec CONTAINER COMMAND.
  • Need the main application’s terminal: use docker attach only with its signal behavior understood.
  • Need Docker control from a workstation: use an SSH context or DOCKER_HOST, not an unauthenticated TCP socket.
  • Need a container to serve SSH as its application: design and secure that published service separately; do not confuse it with routine container administration.

For the ordinary VPS administration case, the reliable answer is host SSH followed by Docker’s process-level access: identify the container, ensure it is running, and execute the shell or command that the image actually provides.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.