简体   繁体   中英

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM