-1

Does someone know how to start and stop services inside the container?

E.g. wish to stop sshd service INSIDE the Ubuntu container, but not in the whole host (RHEL).

J. Doe
  • 23
  • 4
  • Have you checked this issue on serverfault? https://serverfault.com/questions/724553/how-to-prevent-attach-or-exec-in-a-docker-container – JustLudo Nov 19 '20 at 08:34
  • A Docker container runs one process; it does not run "services" _per se_, and commands like `service` don't usually work. – David Maze Nov 19 '20 at 11:11

2 Answers2

0

you need to get a root shell in the container with docker exec -it <container_name> /bin/bash then you can run the command that you want

Kroustou
  • 659
  • 5
  • 14
0
  1. Log in to the container using the below command

    docker exec -it <container_id> /bin/bash

  2. Using any of the below commands can stop the ssh service

    $ sudo /etc/init.d/ssh stop or $ sudo service ssh stop or $ sudo systemctl stop ssh

Ashok
  • 3,190
  • 15
  • 31
  • The problem is that I'm using Centos. It says that `root@3904ba96d9b2:/# /etc/init.d/ssh start bash: /etc/init.d/ssh: No such file or directory` – J. Doe Nov 19 '20 at 19:22