0

I want to simulate user trafic (for tests purposes on a product), that's why I want to run a container which would start a SSH connection and run htop (to simulate user trafic) on a remote machine.

To do that, I created :

  • A container which runs a sshd daemon and added RUN echo "htop" > /home/user/.profile. Then, when a user connects on the container, the htop command is run automatically. It works fine. Here is the code if you want to test.
FROM ubuntu:20.04
ENV TERM xterm
RUN apt update
RUN apt install -y htop openssh-server screen --no-install-recommends
RUN mkdir /var/run/sshd
RUN sed -i "s/#Port 22/Port 22/" /etc/ssh/sshd_config
RUN useradd -rm -d /home/user -s /bin/bash user
RUN  echo 'user:mypassword' | chpasswd
RUN echo "htop" > /home/user/.bashrc
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
CMD ["/usr/sbin/sshd", "-D"]

The associated docker-compose.yml file.

version: "3.3"
services:
  ssh_server_1:
    build:
      context: .
      dockerfile: Dockerfile
    image: ssh_server:0.1
    container_name: ssh_server_1
    ports:
      - "2222:22"

Then if on your host machine you run sshpass -p mypassword ssh -p 2222 -t -o "StrictHostKeyChecking no" user@127.0.0.1 we can see that the htop is started immediately after the user connection. So it works.

  • Now I want to run another container which would connect on the SSH server we just created above and would see the htop content on the screen (to simulate user trafic / actions for tests purposes).
FROM ubuntu:20.04
RUN apt update
RUN DEBIAN_FRONTEND="noninteractive" apt install -y openssh-client sshpass
ENV TERM xterm-256color
CMD sshpass -p mypassword ssh -p 2222 -t -o "StrictHostKeyChecking no" user@<host_ip>

The associated docker-compose.yml file.

version: "3.3"
services:
  ssh_client_1:
    build:
      context: .
      dockerfile: Dockerfile
    image: ssh_client:0.1
    container_name: ssh_client_1
    tty: true
    stdin_open: true

But I get the following result and can't see the output of the htop command.

[...]
Successfully tagged ssh_client:0.1
Recreating ssh_client_1 ... done
Attaching to ssh_client_1
ssh_client_1    | Warning: Permanently added 'xxxxxx' (ECDSA) to the list of known hosts.
[...]
ssh_client_1    | Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-80-generic x86_64)
ssh_client_1    | 
ssh_client_1    |  * Documentation:  https://help.ubuntu.com
ssh_client_1    |  * Management:     https://landscape.canonical.com
ssh_client_1    |  * Support:        https://ubuntu.com/advantage
ssh_client_1    | 
ssh_client_1    | This system has been minimized by removing packages and content that are
ssh_client_1    | not required on a system that users do not log into.
ssh_client_1    | 
ssh_client_1    | To restore this content, you can run the 'unminimize' command.
ssh_client_1    | Last login: Tue Aug 10 14:36:18 2021 from xxxxxx

I tried to change the TERM value to something else like vt100 but it changes nothing.

Why can't I see the htop output ? (note that I will run the container in detached mode at the end).

I don't want to use remote command execution.

I want these containers to use a real shell.

Any idea ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.