NotSoShabby
NotSoShabby

Reputation: 3678

Starting service only if its not already up - docker-compose

I have a docker-compose file that controls a few services. One of which are a db service. I don't always want to restart the db service.

Example docker-compose.yml:

version: '3'
services:
  base:
    commad: "echo somecommand"
  postgres:
    container_name: postgres
    image: "postgres:latest"
    environment:
      - POSTGRES_PASSWORD=usr
      - POSTGRES_USER=use
      - POSTGRES_DB=usr
    ports:
      - 5432:5432

How can I do docker-compose up, but if the db service (postgres in my case) is already up, making sure it wont restart.

Im currently using docker-compose down/up, and my db restarts.

I tried to add --scale postgres=0 to my docker-compose up command, but then it shuts down postgres all together.

Upvotes: 7

Views: 4800

Answers (1)

Siyu
Siyu

Reputation: 12079

Use docker-compose up --no-recreate.

Ref https://docs.docker.com/compose/reference/up/

Upvotes: 14

Related Questions