Persistent user for container

Is there any way to user created in a container when i recreate a container?
I’m using Ubuntu image to create a container to ssh into to modify a few file.
I don’t wan’t to use the root user to ssh so i’m creating a user to ssh with and it’s working but if i recreate the container, my user needs to be recreated.

I’m using compose to builld the conaitner

      image: ubuntu:latest
      container_name: school_ssh
      tty: true
      restart: unless-stopped
        - "./web:/home/websandbx"
        - "./ssh-conf:/etc/ssh"
       - "2200:22"

I haven’t seen any info on that subject,
I’m pretty sure I only need to keep the file that are used to configure the user, it’s password and it’s goup in volumes but I’m not sure which one

Create your own image using a Dockerfile and the docker build command or just use compose for it. The official ubuntu base image wouldn’t work as you need the SSH daemon in the container.

You can use the useradd command in in the Dockefile to add a new user.

Or you can just use an existing image which was built exactly for this purpose

and set the user id and group id as a parameter. I haven’t checked but I guess it creates the user in the entrypoint script when you start the container.