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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化