Dockerize Laravel流明

时间:2019-03-29 20:21:48

标签: laravel docker docker-compose dockerfile lumen

我有Laravel Lumen项目

我有一个Dockerfile。

FROM alpine:3.7

RUN apk --no-cache add \
php7 \
php7-fpm \
php7-pdo \
php7-mbstring \
php7-xml \
php7-openssl \
php7-json \
php7-phar \
php7-zip \
php7-dom \
php7-session \
php7-zlib && \
php7 -r "copy('http://getcomposer.org/installer', 'composer-setup.php');" && \
php7 composer-setup.php --install-dir=/usr/bin --filename=composer && \
php7 -r "unlink('composer-setup.php');" && \
ln -sf /usr/bin/php7 /usr/bin/php && \
ln -s /etc/php7/php.ini /etc/php7/conf.d/php.ini

RUN set -x \
addgroup -g 82 -S www-data \
adduser -u 82 -D -S -G www-data www-data

COPY . /src
ADD .env.example /src/.env
WORKDIR /src
RUN chmod -R 777 storage
CMD php -S localhost:8000 -t public

我也有docker-compose.yml

version: '3'
services:
  portalmodules:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 8000:8000

当我运行docker-compose up时,一切似乎都成功了

Creating network "lumen_default" with the default driver                               
Building portalmodules                                                                 
Step 1/9 : FROM alpine:3.7                                                             
3.7: Pulling from library/alpine                                                       
5d20c808ce19: Downloading [>                                                  ]  21.15k5d20c808ce19: Downloading [============================>                      ]  1.195M5d20c808ce19: Extracting [>                                                  ]  32.77kB5d20c808ce19: Extracting [=====================>                             ]  917.5kB5d20c808ce19: Extracting [==================================================>]  2.107MB5d20c808ce19: Pull complete                                                            
Digest: sha256:fea30b82fd63049b797ab37f13bf9772b59c15a36b1eec6b031b6e483fd7f252        
Status: Downloaded newer image for alpine:3.7                                          
 ---> 6d1ef012b567                                                                     
Step 2/9 : LABEL maintainer "John Doe <john@site.com>"                        
 ---> Running in fb4f2dd6d1de                                                          
Removing intermediate container fb4f2dd6d1de                                           
 ---> 8a45db7ddab9                                                                     
Step 3/9 : RUN apk --no-cache add php7 php7-fpm php7-pdo php7-mbstring php7-xml php7-openssl php7-json php7-phar php7-zip php7-dom php7-session php7-zlib && php7 -r "copy('http://getcomposer.org/installer', 'composer-setup.php');" && php7 composer-setup.php --install-dir=/usr/bin --filename=composer && php7 -r "unlink('composer-setup.php');" && ln -sf /usr/bin/php7 /usr/bin/php && ln -s /etc/php7/php.ini /etc/php7/conf.d/php.ini   
 ---> Running in 3de805731cad                                                          
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz            
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz       
(1/19) Installing php7-common (7.1.17-r0)                                              
(2/19) Installing ncurses-terminfo-base (6.0_p20171125-r1)                             
(3/19) Installing ncurses-terminfo (6.0_p20171125-r1)                                  
(4/19) Installing ncurses-libs (6.0_p20171125-r1)                                      
(5/19) Installing libedit (20170329.3.1-r3)                                            
(6/19) Installing pcre (8.41-r1)                                                       
(7/19) Installing libxml2 (2.9.8-r1)                                                   
(8/19) Installing php7 (7.1.17-r0)                                                     
(9/19) Installing php7-dom (7.1.17-r0)
(10/19) Installing php7-fpm (7.1.17-r0)
(11/19) Installing php7-json (7.1.17-r0)
(12/19) Installing php7-mbstring (7.1.17-r0)
(13/19) Installing php7-openssl (7.1.17-r0)
(14/19) Installing php7-pdo (7.1.17-r0)
(15/19) Installing php7-phar (7.1.17-r0)
(16/19) Installing php7-session (7.1.17-r0)
(17/19) Installing php7-xml (7.1.17-r0)
(18/19) Installing libzip (1.3.0-r1)
(19/19) Installing php7-zip (7.1.17-r0)
Executing busybox-1.27.2-r11.trigger
OK: 25 MiB in 32 packages
All settings correct for using Composer
Downloading...

Composer (version 1.8.4) successfully installed to: /usr/bin/composer
Use it: php /usr/bin/composer

Removing intermediate container 3de805731cad
 ---> ff5d58488a6d
Step 4/9 : RUN set -x addgroup -g 82 -S www-data adduser -u 82 -D -S -G www-data www-data
 ---> Running in 634b56b930cd
Removing intermediate container 634b56b930cd
 ---> 395f7f861700
Step 5/9 : COPY . /src
 ---> 0b4e7b92df73
Step 6/9 : ADD .env.example /src/.env
 ---> 2848f770f17d
Step 7/9 : WORKDIR /src
 ---> Running in cbba620f9904
Removing intermediate container cbba620f9904
 ---> 819ee9222de7
Step 8/9 : RUN chmod -R 777 storage
 ---> Running in 135b707d5008
Removing intermediate container 135b707d5008
 ---> 4bf78fca1236
Step 9/9 : CMD php -S localhost:8000 -t public
 ---> Running in 55d0a643fb43
Removing intermediate container 55d0a643fb43
 ---> bb0d3d1da9a9
Successfully built bb0d3d1da9a9
Successfully tagged lumen_portalmodules:latest
WARNING: Image for service portalmodules was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating lumen_portalmodules_1 ... done                                                
Attaching to lumen_portalmodules_1
portalmodules_1  | PHP 7.1.17 Development Server started at Fri Mar 29 20:16:45 2019

但是我不知道URL是什么-我应该去看看我的网站...♂️

我尝试去过:http://localhost:8000/

我一直得到这个

我做错什么了吗?我的网站网址是什么?

1 个答案:

答案 0 :(得分:2)

您是否尝试过:CMD php -S 0.0.0.0:8000 -t public

localhost引用的是容器本地ip,而不是主机的