Cloud sql proxy not working from docker container

narayansharma91

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?

narayansharma91

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;"

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Spring Cloud Config in Docker container is not accessible

分類Dev

Executing SQL scripts on docker container

分類Dev

Docker-compose container connection to MySql not working

分類Dev

Google Cloud Composer and MS SQL using Cloud Proxy

分類Dev

SQL Server docker container stop after initializing

分類Dev

Access host database from a docker container

分類Dev

Docker replicate UID/GID in container from host

分類Dev

Copy folder with wildcard from docker container to host

分類Dev

docker stop spark container from exiting

分類Dev

docker copy file from one container to another?

分類Dev

How to mount volume from container to host in Docker?

分類Dev

Access vagrant VMs from inside docker container

分類Dev

How to redirect command output from docker container

分類Dev

Can't connect to db from docker container

分類Dev

Docker: Unable to connect to container from host

分類Dev

Web container cannot call backend container from docker compose

分類Dev

Can I seed a mongodb docker container from an other docker container without docker-compose?

分類Dev

docker for windows how to access docker daemon from container

分類Dev

How to stop Docker process from docker hub container busybox?

分類Dev

How to run docker in docker in Container-optimized OS on Compute Engine VM on Google Cloud?

分類Dev

Git push action is not working when pushing from git action container

分類Dev

Different groups from jenkins job's shell and bash on docker container

分類Dev

How to exclude app settings from a docker image (and add them to the container)?

分類Dev

RUN Powershell Script in Docker Container From Host Powershell Script

分類Dev

Generating a dump file from PostgreSQL database inside a Docker container

分類Dev

Can I "rehydrate" a docker build cache from a remote container repository?

分類Dev

Connection from Express App to MongoDB container refused with Docker-Compose

分類Dev

Dockerfile: Copy directory from Windows host to docker container

分類Dev

Docker's container with --net=host is not reachable from the network

Related 関連記事

  1. 1

    Spring Cloud Config in Docker container is not accessible

  2. 2

    Executing SQL scripts on docker container

  3. 3

    Docker-compose container connection to MySql not working

  4. 4

    Google Cloud Composer and MS SQL using Cloud Proxy

  5. 5

    SQL Server docker container stop after initializing

  6. 6

    Access host database from a docker container

  7. 7

    Docker replicate UID/GID in container from host

  8. 8

    Copy folder with wildcard from docker container to host

  9. 9

    docker stop spark container from exiting

  10. 10

    docker copy file from one container to another?

  11. 11

    How to mount volume from container to host in Docker?

  12. 12

    Access vagrant VMs from inside docker container

  13. 13

    How to redirect command output from docker container

  14. 14

    Can't connect to db from docker container

  15. 15

    Docker: Unable to connect to container from host

  16. 16

    Web container cannot call backend container from docker compose

  17. 17

    Can I seed a mongodb docker container from an other docker container without docker-compose?

  18. 18

    docker for windows how to access docker daemon from container

  19. 19

    How to stop Docker process from docker hub container busybox?

  20. 20

    How to run docker in docker in Container-optimized OS on Compute Engine VM on Google Cloud?

  21. 21

    Git push action is not working when pushing from git action container

  22. 22

    Different groups from jenkins job's shell and bash on docker container

  23. 23

    How to exclude app settings from a docker image (and add them to the container)?

  24. 24

    RUN Powershell Script in Docker Container From Host Powershell Script

  25. 25

    Generating a dump file from PostgreSQL database inside a Docker container

  26. 26

    Can I "rehydrate" a docker build cache from a remote container repository?

  27. 27

    Connection from Express App to MongoDB container refused with Docker-Compose

  28. 28

    Dockerfile: Copy directory from Windows host to docker container

  29. 29

    Docker's container with --net=host is not reachable from the network

ホットタグ

アーカイブ