log / partially executing services in docker compose

In Docker Compose, you can selectively execute services defined in your docker-compose.yml file. This is particularly useful during development or troubleshooting when you want to start a specific service without starting the entire stack.

Consider the following docker-compose.yml file:

version: "3"

services:
  webserver:
    image: nginx:latest
    ports:
      - 80:80
      - 443:443
    restart: always
    volumes:
      - ./nginx/conf/:/etc/nginx/conf.d/:ro
      - ./certbot/www:/var/www/certbot/:ro
      - ./certbot/conf/:/etc/nginx/ssl/:ro
  certbot:
    image: certbot/certbot:latest
    volumes:
      - ./certbot/www/:/var/www/certbot/:rw
      - ./certbot/conf/:/etc/letsencrypt/:rw

Suppose you only want to start the webserver service. You can achieve this by using the following command:

docker-compose up webserver -d

This command tells Docker Compose to only start the webserver service in detached mode (-d), ignoring other services defined in the docker-compose.yml file. This way, you can efficiently manage and test individual components of your application without starting unnecessary services.

Written on 2024-03-23 01:44:00 +0700 Edited on 2024-03-23 01:47:00 +0700