defekas17
defekas17

Reputation: 171

executing shell command in docker composer gives me error

I'm trying to execute shell command in docker-compose.yml. Code is:

    command: bash -c mkdir /opt/wa/usr/install_templates

When I do:

    sudo docker-compose up  serviceA

it gives me :

    serviceA     | mkdir: missing operand

Upvotes: 0

Views: 1012

Answers (1)

cam
cam

Reputation: 5198

When you use bash -c, it runs the first string after the -c flag. See this SO answer for more information. Docker is reading your command bash -c mkdir /path/ and your bash command is just running mkdir in a bash subshell, causing that error.

You don't need to put bash -c before your commands in a docker-compose file. The Docker engine will handle running it in a shell for you and you can simply write the command you want to be run. I'd suggest replacing your command with this:

command: mkdir /opt/wa/usr/install_templates

Alternatively, you could try putting the entire command into a string if you want to force the command to be run in bash:

command: bash -c "mkdir /opt/wa/usr/install_templates"

Upvotes: 2

Related Questions