Reputation: 1905
I am trying to make my docker-compose status up and running by trying below docker-compose yaml, but seems when I execute docker-compose ps
, I see the container is stopped, how do I make my docker-compose up
and running for infinite times
docker-compose.yml
version: "3.7"
services:
execute:
command: tail -f /dev/null
image: abc/SREBlackBoxTester
labels:
- mylabelOne= "SREBlackBoxTester"
volumes:
- type: volume
source: AWS_CREDENTIALS_FOLDER
target: /home/scar/.aws
source: SCAR_CONFIG_FOLDER
target: /home/scar/.scar
volume:
nocopy: true
command: bash -c "while true; do sleep 10; done"
volumes:
AWS_CREDENTIALS_FOLDER:
SCAR_CONFIG_FOLDER:
Here goes Docker file
FROM python:3.8-alpine
RUN apk add zip unzip
RUN addgroup --system scar && adduser -S -G scar scar
USER scar
WORKDIR /home/scar/
RUN mkdir /home/scar/.scar && \
mkdir /home/scar/.aws && \
echo '[default]' > /home/scar/.aws/config && \
echo 'region=us-west-2' >> /home/scar/.aws/config && \
echo '[default]' > /home/scar/.aws/credentials && \
echo 'aws_access_key_id=AX' >> /home/scar/.aws/credentials && \
echo 'aws_secret_access_key=wctKx/KdRCSQ' >> /home/scar/.aws/credentials
ENV PATH=/home/scar/.local/bin:$PATH
ENV SCAR_LOG_PATH=/home/scar/.scar/
RUN pip3 install scar --user
CMD scar init -n SREBlack -i image
ENTRYPOINT /bin/sh
The output of docker ps -a
$ docker ps -a
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
f5af892b3b19 abc/image "/bin/sh -c /bin/sh …"
Less than a second ago Exited (0) Less than a second ago
clever_wescoff
Upvotes: 1
Views: 1271
Reputation: 158908
In general a Docker container should be set up to run a specific program. In most cases the default shouldn't be an interactive shell or an artificial tail -f /dev/null
command. In your example nothing is actually running the program you install. You should change the end of the Dockerfile to actually run it
FROM python:3.8-alpine
RUN pip install scar
CMD scar
and provide details like credentials through volumes:
mounts. (Consider whether embedding your AWS credentials into a Docker image has compromised them; anyone who has the image can do anything they're allowed to according to your IAM permissions.)
In the example you show the combination of ENTRYPOINT
and command:
leads to a non-sensical command line. The Dockerfile documentation on Understand how CMD and ENTRYPOINT interact has technical details. Since you specified a shell-format ENTRYPOINT
it gets wrapped in sh -c
, and then the command:
from the docker-compose.yml
file gets appended to that. You wind up with something like
/bin/sh -c '/bin/sh' tail -f /dev/null
which just launches a shell (the "tail ...
" is ignored), and since there's no input, it immediately exits.
In general Docker Compose is more oriented to running long-running applications, like databases or Web servers. The SCAR documentation has an example of running the tool in Docker. For command-line tools like this, though, given the need to do things like manually push AWS credentials from the host into the container and to have root-equivalent permissions to run the tool at all, you might find it more convenient to run the tool directly on the host, maybe installed in a Python virtual environment.
Upvotes: 1
Reputation: 2855
Your docker-compose
file is setting two commands for the container
command: tail -f /dev/null
and (is bash already included in the docker image)
command: bash -c "while true; do sleep 10; done"
you only can use one per service and you need to make sure that the command does not exit.
can you provide the logs of the containers
docker logs ${container_name}
Upvotes: 0