doutang1856
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="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

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

EDIT:

➜ 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

Which seems to mean that everything is ok

But I can't reach my app on 127.0.0.1

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.

    点赞 评论

相关推荐 更多相似问题