patterndockerMinor
docker-compose exec does not execute command even when container is running
Viewed 0 times
containerevendockerrunningcomposedoeswhenexeccommandnot
Problem
I have a docker-compose-custom.yml file like this:
I want to execute a simple command within the container after this one started to run using
I expect
But it displays nothing in the console, it simply returns.
My
How to make it work?
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 installI 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.2How to make it work?
Solution
You messed up with the syntax.
Your command should be like:
$ docker-compose exec -h
Execute a command in a running container
Usage: exec [options] [-e KEY=VAL...] [--] SERVICE COMMAND [ARGS...]Your command should be like:
docker-compose -f docker-compose-custom.yml exec myapp-back-preproduction npm install-p switch is for specifying a project name: identifier that used to construct container name like __1Code Snippets
$ docker-compose exec -h
Execute a command in a running container
Usage: exec [options] [-e KEY=VAL...] [--] SERVICE COMMAND [ARGS...]docker-compose -f docker-compose-custom.yml exec myapp-back-preproduction npm installContext
StackExchange DevOps Q#15146, answer score: 2
Revisions (0)
No revisions yet.