2018-10-25 19:58
浏览 75

在本地访问我的dockerized Laravel应用程序

I am trying to dockerize a PHP / Laravel / VueJS app.

Here is the Dockerfile

FROM php:7.2-fpm
LABEL maintainer=""
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 APP_DIR="/var/www"
ENV DOCKER_FOLDER="docker/local"

RUN echo "deb 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

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

RUN curl -sS | 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- | bash \
&& [ -s "$NVM_DIR/" ] && . "$NVM_DIR/" \
&& 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
CMD php artisan serve --host= --port=$APP_PORT

the last line is supposed to run local server

Then I build it with :

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

Then I run it with:

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

I can see on terminal the output:

[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,>80/tcp   youthful_keldysh

Which seems to mean that everything is ok

But I can't reach my app on

What am I missing

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongweihuan8832 2018-11-19 15:54

    I solved it with this command:

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

    Just remove -d bash at the end, and it should be OK

    点赞 评论
  • dongnang8192 2018-10-25 20:06

    You have to add host configuration file while using docker and add an entry for it inside /etc/hosts and try again.

    点赞 评论

相关推荐 更多相似问题