简体   繁体   中英

Docker Compose to only start the containers

I have 4 containers that i have created via 'docker create' and 'docker run' command. currently i start the containers one by one using below commands as they have dependency:

docker start a docker start b docker start c docker start d

can i only start the containers using docker-compose or do i need to build also using docker compose first. I am using direct solution from the GIT so converting everything to docker-compose will be lot of effort, so wanted to confirm the same. I tried using docker compose up -d with specifying one of the container as service in the docker-compose.yaml file but it failed calling out for the dependent container volume declaration.

docker-compose up doesn't build containers, it just starts them.

Replace build in your compose file with image if you have already built the images and just run them using the mentioned command. If you have dependencies between your containers/services, you can use depends_on to tell docker which containers/services should be started before the one that depends on them.

your docker compose-file could look something like this

...
services:
  service_a:
    image: a
    ...
  service_b:
    image: b
    depends_on:
      - service_a
    ...
  service_c:
    image: c
    depends_on:
      - service_b
    ...
  service_d:
    image: d
    depends_on:
      - service_c
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM