Search code examples
dockerdocker-composeyiidockerfile

running existing yii1 application in docker


I have a existing yii1 application. And I am using local xampp.

So I try to dockerise the existing yii1 application.

So This is my dockerfile in root folder:

FROM php:8.1-apache as dev

ENV DEBIAN_FRONTEND=noninteractive
ENV APP_ENV=development

WORKDIR /var/www/html

RUN apt-get update \
  && apt-get -y install --no-install-recommends apt-utils zip unzip nano ncdu 2>&1 \
    && apt-get -y install --no-install-recommends python graphviz 2>&1 \
  && apt-get -y install git iproute2 procps lsb-release \
  && apt-get install -y -qq software-properties-common \
  && apt-get install -y -qq wget git lynx ack-grep \
  && yes | pecl install xdebug \
  && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
    && apt-get -y install libicu-dev \
    && docker-php-ext-install intl pdo_mysql opcache \
    && pecl install apcu && docker-php-ext-enable apcu \
    && echo "apc.enable_cli=1" > /usr/local/etc/php/php.ini \
    && echo "apc.enable=1" > /usr/local/etc/php/php.ini \
  && echo "post_max_size = 100M" > /usr/local/etc/php/php.ini \
    && a2enmod rewrite \
  && apt-get autoremove -y \
  && apt-get clean -y \
  && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install gnupg2 -y

RUN rm -rf /etc/apache2/sites-enabled \
    && ln -s /var/www/html/.devcontainer/sites-enabled /etc/apache2/sites-enabled

RUN echo 'alias ll="ls -la --color=auto"' >> ~/.bashrc && \
    echo "alias ack='ack-grep'" >> ~/.bashrc

RUN chown www-data:www-data -R ./

ENV DEBIAN_FRONTEND=dialog

and this is my docker-compose.yml file also in root folder:

version: '3'
services:
  web:
    image: nguyenmanhluu/yii1:1.0
    container_name: dockeryiidisc
    ports:
      - "9002:80"
    build: .     
    volumes:
      - ../:/var/www/html       
    command: /bin/sh -c "service apache2 start && while sleep 1000; do :; done"
   
  db:
    container_name: dockeryiimysql
    image: mysql:latest
    volumes:
      - dockeryiimysql:/var/lib/mysql
    ports:
      - "3306:3306"
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
      MYSQL_DATABASE: sdi      

  phpmyadmin:  
    container_name: dockeryiipma
    image: phpmyadmin:latest
    environment:
      UPLOAD_LIMIT: 300M
      PMA_ARBITRARY: 1
      APACHE_HTTP_PORT_NUMBER: 8080
    ports:
      - 8080:8080
    command: /bin/bash -c "sed -i \"s/80/$$APACHE_HTTP_PORT_NUMBER/g\" /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf && /docker-entrypoint.sh apache2-foreground"

volumes:
  dockeryiimysql: {}

So if I go to my root folder and do a docker-compose up. Then I see in docker desktop all three containers are running.

And if I go to: localhost:8080 I see the phpmyadmin database.

But if I go to localhost:9002 I see the startscreen of xampp. And I dont be redirected to the real application.

So what I have to change?

Thank you.

What I mean I will be redirected to: http://localhost:9002/dashboard/


Solution

  • I solved, like this:

    version: '3'
    services:
      web:
        image: nguyenmanhluu/yii1:1.0
        container_name: dockeryiidisc
        ports:
          - "8082:80"
        build: 
          context: ..
          dockerfile: Dockerfile
          target: dev     
        volumes:
          - ./:/var/www/html       
        command: /bin/sh -c "service apache2 start && while sleep 1000; do :; done"
       
      db:
        container_name: dockeryiimysql
        image: mysql:latest
        volumes:
          - dockeryiimysql:/var/lib/mysql
        ports:
          - "3306:3306"
        environment:
          MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
          MYSQL_DATABASE: sdi      
    
      phpmyadmin:  
        container_name: dockeryiipma
        image: phpmyadmin:latest
        environment:
          UPLOAD_LIMIT: 300M
          PMA_ARBITRARY: 1
          APACHE_HTTP_PORT_NUMBER: 8080
        ports:
          - 8080:8080
        command: /bin/bash -c "sed -i \"s/80/$$APACHE_HTTP_PORT_NUMBER/g\" /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf && /docker-entrypoint.sh apache2-foreground"
    
    volumes:
      dockeryiimysql: {}