How to enable ssh access in AIO

I have AIO in docker and i have installed openssh and started it inside nextcloud container and everything fine, but now i need to expose port 22 as 822 in the host to connect, how can i modify container to map port 822 to 22?

i need this also direct ssh access to nextcloud container, without having to run docker exec nextcloud bash… how is this possible ?

It’s impossible out of the box because there is no SSH daemon running inside the container, as there shouldn’t be.

You could theoretically do it by setting up supervisord to run sshd, but you’ll go to a lot of trouble and introduce a larger attack surface unnecessarily.

To install ssd inside running container is easy just run docker exec bash and run following commands:

apk update
apk add openssh
ssh-keygen -A
rc-service sshd start
touch /run/openrc/softlevel
rc-service sshd start

The problem is nextcloud container doesnt have the ssh port mapped, how to just stop and rerun the aio-nextcloud container exposing port 822->22 ?

you will find required installation in Docker docs.

It is strongly not recommended to mangle with containers.

P.S. I moved other posts from another topics here to keep everything together.

I understand it is not recommended but in some cases is needed and any help on achieving is welcome. I am in the point that ssh is already installed and working but need to add the ssh port mapping and expose in the aio-nextcloud container, any help on this?

Hi @albertog, can you please clarify why you need direct ssh access to the container and cannot connect via ssh to the server and then run docker exec … ?

because i need to integrate it with an application that needs ssh/sftp access for monitoring.

because i need to integrate it with an application that needs ssh/sftp access for monitoring.

Then ssh to the underlying host and open a shell in/into the container from the host via docker exec/docker compose exec. It’s literally the point of that.

Or monitor the host rather than the container (depending on what you mean by monitoring).

It’s highly unusual to ssh into a Docker container directly. This isn’t specific to Nextcloud.

Technically it’s possible, and I know I’m just some random person on the Internet, but hear me out: if you have to ask how to get ssh running in a Docker container it usually suggests an oversight in the approach being taken to solving the problem. You’re creating more work for yourself in like 99% of cases.

1 Like

All of your changes will get blown away at the next image update. This isn’t how one makes changes to Docker images.

1 Like

I understand all you said that changes get lost and is more overwork, but i need to do for this case. It is not about if it is good practice or not, we need to access by ssh/sftp this is not a prod environment. If anyone know how to restart the container with the exposed port will be helpful