在本地访问我的dockerized Laravel应用

时间:2018-10-25 19:58:02

标签: php laravel docker

我正在尝试对PHP / Laravel / VueJS应用进行泊坞化。

这是Dockerfile

FROM php:7.2-fpm
LABEL maintainer="contact@kendozone.com"
LABEL version="1.0.0"
LABEL description="Kendozone is a online tournament webapp coded with PHP / Laravel"

ENV node_version 10.8.0
ENV npm_version 6.4.1
ENV NVM_DIR /.nvm
ENV APP_DIR="/var/www"
ENV APP_PORT="80"
ENV DOCKER_FOLDER="docker/local"

RUN echo "deb http://ftp.de.debian.org/debian stretch main " >> /etc/apt/sources.list \
&& apt-get update -y 
RUN apt-get install -y openssl zip unzip git gcc make automake \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
        libmagickwand-dev vim --no-install-recommends
RUN apt-get purge --auto-remove -y g++ \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install pdo pdo_mysql mbstring zip -j$(nproc) iconv  -j$(nproc) gd

WORKDIR $APP_DIR
COPY . $APP_DIR
RUN ls $APP_DIR \
&& touch $APP_DIR/database/sqlite.db \
&& mv $DOCKER_FOLDER/.env.local .env \
&& chown -R www-data:www-data $APP_DIR

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

RUN mkdir -p $NVM_DIR && chown -R www-data:www-data $NVM_DIR \
&&  curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash \
&& [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" \
&& nvm install ${node_version}

ENV NODE_PATH $NVM_DIR/v$node_version/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$node_version/bin:$PATH

RUN npm install --save-exact imagemin-pngquant@5.0.*  \
&& npm install \
&& npm run production \
&& php artisan key:generate \
&& php artisan migrate --seed
EXPOSE $APP_PORT
CMD php artisan serve --host=0.0.0.0 --port=$APP_PORT

最后一行应该运行本地服务器

然后我用:

docker build . -t xoco/kendozone:local-1.0.3 

然后我用以下命令运行它:

docker run -p 80:80 xoco/kendozone:local-1.0.3 -d bash

我可以在终端上看到输出:

[25-Oct-2018 19:56:40] NOTICE: fpm is running, pid 1
[25-Oct-2018 19:56:40] NOTICE: ready to handle connections

编辑:

➜ docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                            NAMES
fee456200b85        xoco/kendozone:local-1.0.3   "docker-php-entrypoi…"   2 hours ago         Up 2 hours          9000/tcp, 0.0.0.0:8080->80/tcp   youthful_keldysh

这似乎意味着一切正常

但是我无法在127.0.0.1上访问我的应用

我想念什么

2 个答案:

答案 0 :(得分:0)

您必须在使用docker时添加主机配置文件,并在/etc/hosts中为其添加条目,然后重试。

答案 1 :(得分:0)

我用以下命令解决了它:

docker run -p 80:80 xoco/kendozone:local-1.0.3

只需最后删除-d bash,就可以了