I have a docker-compose-custom.yml file like this:
version: '3.8'
services:
myapp-back-preproduction:
build:
context: .
container_name: myapp-back-preproduction
image: 'myapp-back-preproduction:latest'
....
I want to execute a simple command within the container after this one started to run using docker-compose exec
:
docker-compose -p myapp-back-preproduction -f docker-compose-custom.yml exec npm install
I expect npm install
to be executed within the container.
But it displays nothing in the console, it simply returns.
docker exec
instead works but it logically lacks all environment variables declared in my docker-compose-custom.yml
file; I want to use docker-compose exec
.
My docker-compose
version is: 1.29.2
How to make it work?
docker-compose exec
was lacking these envvars. Once I defined them, it ran successfully. Surprisingly runningexec bash
, envvars were using the values defined in thedocker-compose up
command's shell, not in thedocker-compose exec bash
shell. (Using docker-compose version 1.29.2, docker-compose.yml version 3.7)