I have a docker-compose.yml (simplified example):
version: "3.8"
services:
server:
image: node:lts-slim
container_name: example-container
hostname: example-server
ports:
- 4000:4000
working_dir: /server
volumes:
- ./someLocalDirectory:/server
command: node --watch index.js
I create/start the container with docker-compose up -d server
Problem:
I'd prefer to not have command: node --watch index.js
hardcoded inside the yml file.
Question:
Is it possible to pass command: node --watch index.js
as an argument to docker-compose up -d server
on the command line?
Thanks in advance :)
Solution:
You can prepend key-value-pairs on the command-line and treat them like regular variables inside docker-compose:
key="node --watch index.js" docker-compose up -d server
version: "3.8"
services:
server:
# ... see example above
command: ${key}