I tried to run aws cli image from amazon from docker-compose.
version: '3.1'
services:
web:
image: amazon/aws-cli:latest
stdin_open: true # equivalent of -i
tty: true # equivalent of -t
deploy:
mode: replicated
replicas: 1
resources:
limits:
cpus: "2"
memory: 2048M
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
environment:
- HTTP_PROXY=http://ipadresses:port
- HTTPS_PROXY=https://ipadresses:port
ports:
- "8080:8080"
After one second, the image stops running immediately. I looked for the official documentation from amazon but I cannot find an answer to my question: why it's stop so quickely Could someone please help me understand this behavior?
CodePudding user response:
amazon/aws-cli:latest
is a docker image that provides only the aws command as starting command, which means, if you don't override the command executed by docker the container will execute aws
command and stop the execution.
To execute commands against aws
using that docker image you need to provide your command e.g. in this compose file I'm executing aws help
by adding command: help
to the file.
version: '3.1'
services:
web:
image: amazon/aws-cli:latest
stdin_open: true # equivalent of -i
tty: true # equivalent of -t
command: help
deploy:
mode: replicated
replicas: 1
resources:
limits:
cpus: "2"
memory: 2048M
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
environment:
- HTTP_PROXY=http://ipadresses:port
- HTTPS_PROXY=https://ipadresses:port
ports:
- "8080:8080"
Alternatively you could override entrypoint
to force the container to stay alive, so afterwards you can exec commands against your container e.g
version: '3.1'
services:
web:
image: amazon/aws-cli:latest
stdin_open: true # equivalent of -i
tty: true # equivalent of -t
entrypoint: tail -f /dev/null
deploy:
mode: replicated
replicas: 1
resources:
limits:
cpus: "2"
memory: 2048M
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
environment:
- HTTP_PROXY=http://ipadresses:port
- HTTPS_PROXY=https://ipadresses:port
ports:
- "8080:8080"
After you run this compose file (in another terminal) you can inspect the name of the created container with docker ps
and then execute commands against that using docker exec -it <your_container_name> aws help
(note that in this case I'm sending the command aws help
to the running container)