I am working on a PHP project using Laravel and I have several utilities in my docker-compose
:
composer:
image: composer:latest
container_name: composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- php
networks:
- laravel
npm:
image: node:13.7
container_name: npm
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
entrypoint: ["npm"]
With this I have to prefix each command with docker-compose run -rm
such as:
docker-compose run -rm npm update
Is there a way to simply have an environment that set some aliases (npm
, grunt
, composer
, mysql
...) when I am in that project in VSCode?
You can add a task in VS code
Lots of tools exist to automate tasks like linting, building, packaging, testing, or deploying software systems. Examples include the TypeScript Compiler, linters like ESLint and TSLint as well as build systems like Make, Ant, Gulp, Jake, Rake, and MSBuild.
it should be placed inside .vscode
├── docker-compose.yml
└── .vscode
└── tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "npm",
"type": "shell",
"command": "docker-compose run ${input:npm}",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "composer",
"type": "shell",
"command": "docker-compose run ${input:compose}",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"inputs": [
{
"id": "npm",
"description": "npm argument:",
"default": "npm",
"type": "promptString"
},
{
"id": "compose",
"description": "compose argument:",
"default": "composer",
"type": "promptString"
}
]
}
Now All set, all you need to press
Ctrl+Shift+B and both task will be listed, select and execute the task.