502 Bad Gateway Docker + Laravel











up vote
0
down vote

favorite












I've started to learn Docker. I have Laravel application and want to start it in docker containers. But I can't run it correctly.



I have this docker-compose.yml:



version: '2'
services:

# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"

# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80

# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"

volumes:
dbdata:


And this vhost.conf:



server {
listen 80;
index index.php index.html;
root /var/www/public;

location / {
try_files $uri /index.php?$args;
}

location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}


app.dockerfile:



FROM php:7.1.3-fpm

RUN apt-get update && apt-get install -y
libmagickwand-dev --no-install-recommends
libmcrypt-dev
cron
mysql-client
vim
&& docker-php-ext-install mcrypt pdo_mysql


web.dockerfile:



FROM nginx:1.10

ADD vhost.conf /etc/nginx/conf.d/default.conf


After run containers I have 502 Bad Gateway and in web container I have this:
connect() failed (111: Connections refused) while connecting to upstream, client: 192.168.99.1, server: request "GET /HTTP/1.1", upstream: "fastcgi://172.19.0.3:9000", host: "192.168.99.101:8080".



I very bad at server settings and don't understand what happened. Will be very grateful for every help.










share|improve this question
























  • I cannot tell what exactly is the issue, but your web containers cannot connect to the app containers. Can you try to ping your app container from the web container. ping app. If the containers are not able to ping each other try to include a network that the containers share.
    – Ilyas Deckers
    11 hours ago












  • I can ping from web to app.
    – Alex Lukinov
    11 hours ago















up vote
0
down vote

favorite












I've started to learn Docker. I have Laravel application and want to start it in docker containers. But I can't run it correctly.



I have this docker-compose.yml:



version: '2'
services:

# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"

# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80

# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"

volumes:
dbdata:


And this vhost.conf:



server {
listen 80;
index index.php index.html;
root /var/www/public;

location / {
try_files $uri /index.php?$args;
}

location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}


app.dockerfile:



FROM php:7.1.3-fpm

RUN apt-get update && apt-get install -y
libmagickwand-dev --no-install-recommends
libmcrypt-dev
cron
mysql-client
vim
&& docker-php-ext-install mcrypt pdo_mysql


web.dockerfile:



FROM nginx:1.10

ADD vhost.conf /etc/nginx/conf.d/default.conf


After run containers I have 502 Bad Gateway and in web container I have this:
connect() failed (111: Connections refused) while connecting to upstream, client: 192.168.99.1, server: request "GET /HTTP/1.1", upstream: "fastcgi://172.19.0.3:9000", host: "192.168.99.101:8080".



I very bad at server settings and don't understand what happened. Will be very grateful for every help.










share|improve this question
























  • I cannot tell what exactly is the issue, but your web containers cannot connect to the app containers. Can you try to ping your app container from the web container. ping app. If the containers are not able to ping each other try to include a network that the containers share.
    – Ilyas Deckers
    11 hours ago












  • I can ping from web to app.
    – Alex Lukinov
    11 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I've started to learn Docker. I have Laravel application and want to start it in docker containers. But I can't run it correctly.



I have this docker-compose.yml:



version: '2'
services:

# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"

# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80

# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"

volumes:
dbdata:


And this vhost.conf:



server {
listen 80;
index index.php index.html;
root /var/www/public;

location / {
try_files $uri /index.php?$args;
}

location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}


app.dockerfile:



FROM php:7.1.3-fpm

RUN apt-get update && apt-get install -y
libmagickwand-dev --no-install-recommends
libmcrypt-dev
cron
mysql-client
vim
&& docker-php-ext-install mcrypt pdo_mysql


web.dockerfile:



FROM nginx:1.10

ADD vhost.conf /etc/nginx/conf.d/default.conf


After run containers I have 502 Bad Gateway and in web container I have this:
connect() failed (111: Connections refused) while connecting to upstream, client: 192.168.99.1, server: request "GET /HTTP/1.1", upstream: "fastcgi://172.19.0.3:9000", host: "192.168.99.101:8080".



I very bad at server settings and don't understand what happened. Will be very grateful for every help.










share|improve this question















I've started to learn Docker. I have Laravel application and want to start it in docker containers. But I can't run it correctly.



I have this docker-compose.yml:



version: '2'
services:

# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"

# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80

# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"

volumes:
dbdata:


And this vhost.conf:



server {
listen 80;
index index.php index.html;
root /var/www/public;

location / {
try_files $uri /index.php?$args;
}

location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}


app.dockerfile:



FROM php:7.1.3-fpm

RUN apt-get update && apt-get install -y
libmagickwand-dev --no-install-recommends
libmcrypt-dev
cron
mysql-client
vim
&& docker-php-ext-install mcrypt pdo_mysql


web.dockerfile:



FROM nginx:1.10

ADD vhost.conf /etc/nginx/conf.d/default.conf


After run containers I have 502 Bad Gateway and in web container I have this:
connect() failed (111: Connections refused) while connecting to upstream, client: 192.168.99.1, server: request "GET /HTTP/1.1", upstream: "fastcgi://172.19.0.3:9000", host: "192.168.99.101:8080".



I very bad at server settings and don't understand what happened. Will be very grateful for every help.







laravel docker nginx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 11 hours ago

























asked 12 hours ago









Alex Lukinov

523310




523310












  • I cannot tell what exactly is the issue, but your web containers cannot connect to the app containers. Can you try to ping your app container from the web container. ping app. If the containers are not able to ping each other try to include a network that the containers share.
    – Ilyas Deckers
    11 hours ago












  • I can ping from web to app.
    – Alex Lukinov
    11 hours ago


















  • I cannot tell what exactly is the issue, but your web containers cannot connect to the app containers. Can you try to ping your app container from the web container. ping app. If the containers are not able to ping each other try to include a network that the containers share.
    – Ilyas Deckers
    11 hours ago












  • I can ping from web to app.
    – Alex Lukinov
    11 hours ago
















I cannot tell what exactly is the issue, but your web containers cannot connect to the app containers. Can you try to ping your app container from the web container. ping app. If the containers are not able to ping each other try to include a network that the containers share.
– Ilyas Deckers
11 hours ago






I cannot tell what exactly is the issue, but your web containers cannot connect to the app containers. Can you try to ping your app container from the web container. ping app. If the containers are not able to ping each other try to include a network that the containers share.
– Ilyas Deckers
11 hours ago














I can ping from web to app.
– Alex Lukinov
11 hours ago




I can ping from web to app.
– Alex Lukinov
11 hours ago












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










This is probably caused by php listening on localhost and doe not accept external connections. You should update you php.ini to listen on 0.0.0.0.



you could test this by running the following command on your app container. And try to telnet from the web container to the app container.



/usr/bin/php -S 0.0.0.0:9000

telnet app 9000


If, for some reason that command fails try to edit your php-fpm config to set the listen address to 0.0.0.0:9000



Example:



; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.

listen = 0.0.0.0:9000





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203294%2f502-bad-gateway-docker-laravel%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    This is probably caused by php listening on localhost and doe not accept external connections. You should update you php.ini to listen on 0.0.0.0.



    you could test this by running the following command on your app container. And try to telnet from the web container to the app container.



    /usr/bin/php -S 0.0.0.0:9000

    telnet app 9000


    If, for some reason that command fails try to edit your php-fpm config to set the listen address to 0.0.0.0:9000



    Example:



    ; The address on which to accept FastCGI requests.
    ; Valid syntaxes are:
    ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
    ; a specific port;
    ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
    ; a specific port;
    ; 'port' - to listen on a TCP socket to all addresses
    ; (IPv6 and IPv4-mapped) on a specific port;
    ; '/path/to/unix/socket' - to listen on a unix socket.
    ; Note: This value is mandatory.

    listen = 0.0.0.0:9000





    share|improve this answer

























      up vote
      2
      down vote



      accepted










      This is probably caused by php listening on localhost and doe not accept external connections. You should update you php.ini to listen on 0.0.0.0.



      you could test this by running the following command on your app container. And try to telnet from the web container to the app container.



      /usr/bin/php -S 0.0.0.0:9000

      telnet app 9000


      If, for some reason that command fails try to edit your php-fpm config to set the listen address to 0.0.0.0:9000



      Example:



      ; The address on which to accept FastCGI requests.
      ; Valid syntaxes are:
      ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
      ; a specific port;
      ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
      ; a specific port;
      ; 'port' - to listen on a TCP socket to all addresses
      ; (IPv6 and IPv4-mapped) on a specific port;
      ; '/path/to/unix/socket' - to listen on a unix socket.
      ; Note: This value is mandatory.

      listen = 0.0.0.0:9000





      share|improve this answer























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        This is probably caused by php listening on localhost and doe not accept external connections. You should update you php.ini to listen on 0.0.0.0.



        you could test this by running the following command on your app container. And try to telnet from the web container to the app container.



        /usr/bin/php -S 0.0.0.0:9000

        telnet app 9000


        If, for some reason that command fails try to edit your php-fpm config to set the listen address to 0.0.0.0:9000



        Example:



        ; The address on which to accept FastCGI requests.
        ; Valid syntaxes are:
        ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
        ; a specific port;
        ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
        ; a specific port;
        ; 'port' - to listen on a TCP socket to all addresses
        ; (IPv6 and IPv4-mapped) on a specific port;
        ; '/path/to/unix/socket' - to listen on a unix socket.
        ; Note: This value is mandatory.

        listen = 0.0.0.0:9000





        share|improve this answer












        This is probably caused by php listening on localhost and doe not accept external connections. You should update you php.ini to listen on 0.0.0.0.



        you could test this by running the following command on your app container. And try to telnet from the web container to the app container.



        /usr/bin/php -S 0.0.0.0:9000

        telnet app 9000


        If, for some reason that command fails try to edit your php-fpm config to set the listen address to 0.0.0.0:9000



        Example:



        ; The address on which to accept FastCGI requests.
        ; Valid syntaxes are:
        ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
        ; a specific port;
        ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
        ; a specific port;
        ; 'port' - to listen on a TCP socket to all addresses
        ; (IPv6 and IPv4-mapped) on a specific port;
        ; '/path/to/unix/socket' - to listen on a unix socket.
        ; Note: This value is mandatory.

        listen = 0.0.0.0:9000






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 11 hours ago









        Ilyas Deckers

        539317




        539317






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203294%2f502-bad-gateway-docker-laravel%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            Popular posts from this blog

            Schultheiß

            Liste der Kulturdenkmale in Wilsdruff

            Android Play Services Check