Docker Community Forums

Share and learn in the Docker community.

Docker container is going to STOPPED state in ECR Fargate

Hi guys,

We’re using “php:7.2-cli” image to build and deploy our applications to AWS ECR Fargate.

I’ve an issue, once I build and deploy the application to the ECR repository, and then I configure the task definition and service to start the container, the service fails to start the container normally and the task just go to “STOPPED” state directly with “Essential container in task exited” error.

I think there is something missing in the Dockefile for the container entry point. So, can you please help me fix this issue. Below is my php Dockerfile:

FROM php:7.2-cli

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y --no-install-recommends apt-utils \
&& apt-get install -y gzip git jq \
&& apt-get install -y zip unzip \
&& apt-get install -y libxml2-dev \
&& apt-get install -y openssl \
&& apt-get install -y libssl-dev libcurl4-openssl-dev pkg-config \
&& apt-get install -y libicu-dev g++ libxml2 \
&& apt-get install -y libbz2-dev zlib1g-dev

RUN docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-install -j$(nproc) bcmath \
&& docker-php-ext-install -j$(nproc) zip \
&& docker-php-ext-install -j$(nproc) pcntl soap curl xml mbstring soap

RUN	pecl install xdebug \
&& docker-php-ext-enable xdebug

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN apt-get update && apt-get install -y openssh-server
RUN mkdir -p -m 0700 /root/.ssh
EXPOSE 22

COPY docker-php-ext-* docker-php-entrypoint /usr/local/bin/
RUN chmod a+x /usr/local/bin/docker-php-ext-*
RUN chmod a+x /usr/local/bin/docker-php-entrypoint

COPY ./conf.d /usr/local/etc/php/conf.d
COPY ./php.ini /usr/local/etc/php/php.ini

ENTRYPOINT ["docker-php-entrypoint"]
CMD ["php", "-a"]
CMD ["/usr/sbin/sshd", "-D"]

Thanks,
Ali

You are aware that the last declared CMD is the one beeing used, aren’t you?
And that if an ENTRYPOINT is declared, the CMD will be passed as a parameter to the entrypoint script-

Why would you even want to include a sshd in your image?
There is no reason to apply old world habits to the container world :slight_smile:

Hi Meyay,

Thanks for your reply.

I’m using the sshd because we need to ssh into the ECR Fargate container from our corporate network using VPN.

But even before I include the CMD ["/usr/sbin/sshd", “-D”] command, it was not starting in ECR.

So, before it was like:

ENTRYPOINT [“docker-php-entrypoint”]
CMD [“php”, “-a”]

So, what is wrong in my file.

Unless you share the content of docker-php-entrypoint, there is no way knowing what your entrypoint script does of wheter or how your CMD is used by the entrypoint script.

Here it is:

#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php "$@"
fi

exec "$@"

I got it from Docker Hub repo:
https://github.com/docker-library/php/tree/afa08b1838294089a465f97f87ea7a960039fda0/7.2/stretch/cli

The entrypoint script seems fine and executes the command in CMD.
Appart from advising to use full paths for your entrypoint script and cmd, there seems not much to be wrong.

I used the full path in the entrypoitn as below:

ENTRYPOINT ["/usr/local/bin/docker-php-entrypoint"]

But when I pushed the image to ECR and start the service, the task still exit with stopped state.