Ankur Sharma
Ankur Sharma

Reputation: 45

Start particular service from docker-compose

I am new to Docker and have docker-compose.yml which is containing many services and iI need to start one particular service. I have docker-compose.yml file with information:

version: '2'

services:
    
    postgres:
        image: ${ARTIFACTORY_URL}/datahub/postgres:${BUILD_NUMBER}
        restart: "no"
        volumes:
            - /etc/passwd:/etc/passwd
            

        volumes_from:
            - libs
        depends_on:
            - libs

    setup:
        image: ${ARTIFACTORY_URL}/setup:${B_N}
        restart: "no"
        volumes:
            - ${HOME}:/usr/local/

I am able to call docker-compose.yml file using command:

docker-compose -f docker-compose.yml up -d --no-build

But I need to start "setup service" in docker-compose file:

How can I do this?

Upvotes: 3

Views: 4623

Answers (2)

funder7
funder7

Reputation: 1875

It's very easy:

$ docker compose up <service-name>

In your case:

$ docker compose -f docker-compose.yml up setup -d

To stop the service, then you don't need to specify the service name:

$ docker compose down

will do.

Little side note: if you are in the directory where the docker-compose.yml file is located, then docker-compose will use it implicitly, there's no need to add it as a parameter. You need to provide it in the following situations:

  • the file is not in your current directory
  • the file name is different from the default one, eg. myconfig.yml

Upvotes: 9

Somesh Gupta
Somesh Gupta

Reputation: 287

As far as I understand your question, you have multiple services in docker-compose but want to deploy only one.

docker-compose should be used for multi-container Docker applications. From official docs :

Compose is a tool for defining and running multi-container Docker applications.

IMHO, you should run your service image separately with docker run command.

PS: If you are asking about recreating only the container whose image is changed among the multiple services in your docker-compose file, then docker-compose handles that for you.

Upvotes: -1

Related Questions