skip to Main Content

I am using a postgres image and i need to start ssh service on start.
The problem is that if I run a command in docker-compose file the proccess exits with code 0.

How can I start ssh service but keep postgres serice active too?

DOCKER FILE:

FROM postgres:13

RUN apt update && apt install  openssh-server sudo -y
RUN  echo 'root:password' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config

DOCKER-COMPOSE FILE:

postgres:
    container_name: db_postgres
    command: sh -c "service ssh start "
    image: postgresc
    build:
      context: ../backend_apollo_server_express
      dockerfile: Dockerfile.database
    environment:
      - "POSTGRES_USER=lims"
      - "POSTGRES_PASSWORD=lims"
    volumes:
      - /home/javier/lims/dockerVolumes/db:/var/lib/postgresql/data
      - "/etc/timezone:/etc/timezone:ro"
      - "/etc/localtime:/etc/localtime:ro"
    ports:
      - 5434:5432

2

Answers


  1. Try

    command: sh -c "nohup service ssh start && service postgres start &"
    

    In order to leave the process running in the background. This way the process won’t exit

    Login or Signup to reply.
  2. You can try to use run postgres after you command

    command: sh -c "service ssh start & postgres"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search