Simple docker-compose.yml to setup an Ubuntu container with ssh access and persistent files

Viewed 1314

My goal is to setup a very minimalistic Ubuntu container for hosting a server within it. It should be accessible via ssh and have a persistent configuration.

I am currently having this server running within a virtual machine. This should move to Docker now since I would like to reduce complexity and increase maintainability (I have couple of other containers running perfectly).

What I've tried so far:

  • Created a docker-compose.yml & Dockerfile and connected a local folder
  • Got access to the container with "docker container exec -ti bash"
  • Installed things within this machine, configured ssh

My issues are:

  • The build seems to work, even with configuring ssh
  • SSH via remote does not work - logging in via "docker container exec ... bash" works fine
  • Configuring things within the machine, settings up ssh etc works (same commands like in Dockerfile) - SSH via remote works
  • Shutting down (docker-compose down) and starting up (docker-compose up -d) resets everything I did within the machine

Do you have any ideas, or even a working docker-compose file? Searching for this results in thousands of articles how to install Docker on Ubuntu...

THANK YOU so much!

My Dockerfile looks like this

FROM ubuntu:latest

RUN apt-get update
RUN apt-get install openssh-server -y

RUN mkdir /var/run/sshd

RUN echo 'root:pwd' | chpasswd

# SSH allow root login via remote
RUN sed -i 's/#PermitRootLogin/PermitRootLogin/g' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

# RESTART SSH
RUN /etc/init.d/ssh restart

My docker-compose.yml looks like this

version: "3"
services:

  # ubuntu server
  ubuntu_test:
    build: .
    container_name: AAubuntuServerDockerfile
    restart: always
    command: ["sleep","infinity"]
    volumes:
      - './Docker/Data/Ubuntu_Test:/exchange:rw'
    ports:
      - "5555:22"
    network_mode: bridge
0 Answers
Related