Get docker-compose up to only run certain containers
docker-compose up <service_name>
will start only the service you have specified and its dependencies. (those specified in the dependends_on
option.)
you may also define multiple services in the docker-compose up command:
docker-compose up <service_name> <service_name>
note - what does it mean "start the service and its dependecies"?
usually your production services (containers) are attached to each other via the dependes_on
chain, therefore you can start only the last containers of the chain. for example, take the following compose file:
version: '3.7'
services:
frontend:
image: efrat19/vuejs
ports:
- "80:8080"
depends_on:
- backend
backend:
image: nginx:alpine
depends_on:
- fpm
fpm:
image: php:7.2
testing:
image: hze∂ƒxhbd
depends_on:
- frontend
all the services are chained in the depends_on
option, while the testing container is down bellow the frontend. so when you hit docker-compose up frontend
docker will run the fpm first, then the backend, then the frontend, and it will ignore the testing container, which is not required for running the frontend.