2

My application is running on docker container and deployed with google compute groups and autoscalling enabled. The problem iam facing is connecting mysql instance from auto-scaled compute instances but its not working expected.

Dockerfile

FROM ubuntu:16.04
RUN apt-get update && apt-get install -y software-properties-common && \
...installation other extenstion
RUN curl -sS https://getcomposer.org/installer | \
    php -- --install-dir=/usr/bin/ --filename=composer
COPY . /var/www/html
CMD cd /var/www/html
RUN composer install
ADD nginx.conf/default /etc/nginx/sites-available/default
RUN wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
RUN chmod +x cloud_sql_proxy
RUN mkdir /cloudsql
RUN chmod 777 /cloudsql
RUN chmod 777 -R storage bootstrap/cache
EXPOSE 80
**CMD service php7.1-fpm start && nginx -g "daemon off;" &&  ./cloud_sql_proxy -dir=/cloudsql -instances=<connectionname>=tcp:0.0.0.0:3306 -credential_file=file.json &**

The last line ./cloud_sql_proxy -dir=/cloudsql -instances=<connectionname>=tcp:0.0.0.0:3306 -credential_file=file.json & is not getting executed when I run my container.

If I run this ./cloud_sql_proxy -dir=/cloudsql -instances=<connectionname>=tcp:0.0.0.0:3306 -credential_file=file.json & inside container (by going to container via docker command) it's working and when i close the terminal again its stop working.

Even I tried to run in background, but no luck.

Anyone have a idea of it?

5
  • did you try to change your latest command order and start with the sql proxy command? Commented Feb 17, 2020 at 11:58
  • Could you show the error logs of the Docker build? docs.docker.com/config/containers/logging Commented Feb 18, 2020 at 9:49
  • Now it's working Commented Feb 18, 2020 at 10:05
  • I put sleep 10 on shell script Commented Feb 18, 2020 at 10:05
  • 1
    Great!, It would be great if you added the files in the response and mark it as accepted! stackoverflow.com/help/self-answer Commented Feb 18, 2020 at 10:35

1 Answer 1

3

Has been fixed by

  1. Create start.sh file and move all command to start.sh
  2. After start sql proxy I put sleep 10 and start the nginx and php

Now it's works as expected.

Dockerfile
FROM ubuntu:16.04
...other command
ADD start.sh /
RUN chmod +x /start.sh
EXPOSE 80
CMD ["/start.sh"]

and this is start.sh file

//start.sh
#!/bin/sh
./cloud_sql_proxy -dir=/cloudsql -instances=<connectionname>=tcp:0.0.0.0:3306     -credential_file=<file>.json &
sleep 10
service php7.1-fpm start
nginx -g "daemon off;"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.