问题
I have a Dockerfile
and a Dockerfile.aws.json
:
{
"AWSEBDockerrunVersion": "1",
"Ports": [{
"ContainerPort": "5000",
"HostPort": "5000"
}],
"Volumes": [{
"HostDirectory": "/tmp/download/models",
"ContainerDirectory": "/models"
}],
"Logging": "/var/log/nginx",
"Command": "mkdir -p /tmp && axel https://example.com/models.zip -o /tmp/models.zip"
}
But when I deploy, it doesn't run the Command
that I specified. What am I doing wrong?
回答1:
If you have ENTRYPOINT
in your Dockerfile, than the Command
gets appended as its arguments:
Specify a command to execute in the container. If you specify an Entrypoint, then Command is added as an argument to Entrypoint. For more information, see CMD in the Docker documentation.
Thus your Command mkdir -p /tmp ...
will be used as an argument to python3 -m flask run --host=0.0.0.0
, resulting in error. This could explain why you experience issue.
I tried to recreate the issue initially using your Command
structure but had some problems. What worked was using Command
in the following way:
"Command": "/bin/bash -c \"mkdir -p /tmp && axel https://example.com/models.zip -o /tmp/models.zip\""
My Dockerfile
did not have Entrypoint
. Thus to run your python you could maybe do the following (assuming everything else is correct):
"Command": "/bin/bash -c \"mkdir -p /tmp && axel https://example.com/models.zip -o /tmp/models.zip && python3 -m flask run --host=0.0.0.0\""
回答2:
Do you have the Dockerfile content?
It most likely they your ENTRYPOINT
script does not receive parameters, or it is ignoring it.
What you can do is something similar to this.
You have an entrypoint script that receive the command passed in aws.json as parameter, execute it and then call your real python command.
Or you can replace your ENTRYPOINT
by something similar to this:
ENTRYPOINT ["/bin/bash"]
and your default command will be:
CMD ["python3 ..."]
This way when running locally you only run the python3 command.
When running in aws, you can change your Command and append the python to the end, as mentioned by Marcin. Both cases works
来源:https://stackoverflow.com/questions/62818496/how-do-i-get-a-command-to-run-from-a-dockerfile-aws-json-on-elastic-beanstalk