简体   繁体   中英

Error in executing a command when starting a container using docker-compose

I want to start my container and once it's running, start a service in the container. I'm using a docker-compose file and start my service in the ''command'' section of it as follows

services:
  service1:
    image: image_name:tag
    container_name: cname
    command:
         - exec start_service $VAR1 $VAR2
    ports:
        - "5458:5000"
    env_file: ./variables.txt

values of VAR1 and VAR2 are coming from the variables.txt file which is specified in the env_file section. Also start_service exist in the $PATH of the container. When I start the docker-compose, it first shows some warning that the VAR1 and VAR2 are not set and also errors out with the following error message.

 Cannot start service service1: oci runtime error: container_linux.go:235: starting container process caused "exec: \"exec start_service   \": executable file not found in $PATH".

So it looks like the command is executed before the env variables are set and also it says start_service is not in $PATH which is not true.

What's going wrong here?

ps I did some test and commented the command in the docker-compose, when the container started I went to the container and ensured that start_service exist in the $PATH.

You don't need to put exec before start_service . Docker will do that for you, so if you take a closer look at the error message you'll notice that exec: \\"exec start_service \\"

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