0

I made a PHP app and want to make a Docker image out of it. For my app to work, I need PHP-apache, MySQL, and PhpMyAdmin.

When I run docker-compose up, everything works fine.

So, I did docker ps -a and got:

CONTAINER ID   IMAGE                            COMMAND                  CREATED         STATUS          PORTS                               NAMES
fa19aa03b658   docker2-php-apache-environment   "docker-php-entrypoi…"   9 minutes ago   Up 26 seconds   0.0.0.0:8000->80/tcp                php-apache
cd6a1d03c74c   phpmyadmin/phpmyadmin            "/docker-entrypoint.…"   9 minutes ago   Up 26 seconds   0.0.0.0:8080->80/tcp                docker2-phpmyadmin-1
ff13a69f0fde   mysql                            "docker-entrypoint.s…"   9 minutes ago   Up 27 seconds   33060/tcp, 0.0.0.0:9906->3306/tcp   db

I want to push my project to Docker Hub, but I am not sure how to do it. When I commit and push docker2-php-apache-environment(fa19aa03b658) and pull the image on a different machine, I am missing MySql and PhpMyAdmin.

Is it possible to push the whole project so that when somebody pulls and runs the image, everything works?

I made docker-compose.yml which looks like this:

version: '3.8'
services:
    php-apache-environment:
        container_name: php-apache
        build:
            context: ./php
            dockerfile: Dockerfile
        depends_on:
            - db
        volumes:
            - ./php/src:/var/www/html/ 
        ports:
            - 8000:80
    db:
        container_name: db
        image: mysql
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: 12345
            MYSQL_DATABASE: turisticka_agencija
        ports:
            - "9906:3306"
    phpmyadmin:
      image: phpmyadmin/phpmyadmin
      ports:
          - '8080:80'
      restart: always
      environment:
          PMA_HOST: db
      depends_on:
          - db

Dockerfile looks like this:

FROM php:8.0-apache
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apt-get update && apt-get upgrade -y

# Install build dependencies and the OPcache extension
RUN apk add --no-cache $PHPIZE_DEPS \
    && docker-php-ext-install opcache \
    && apk del $PHPIZE_DEPS

# Copy the opcache.ini into your Docker image    
COPY opcache.ini /usr/local/etc/php/conf.d/opcache.ini

# Run your application
CMD php-fpm
  • Are you sure that the image can be built ? I see `apt-get` and `apk` (Alpine Linux) commands. – AymDev Feb 09 '23 at 15:55
  • If someone need to run your project he would need the Docker Compose file to start the complete stack. If it needs to configure things like the database, you could use a Makefile to automate the setup process ? – AymDev Feb 09 '23 at 15:57
  • Hi! Thanks for helping. Yes, image can be build, those Alpine Linux commands I found somewhere online in order to speed up PHP, it helped a ton so I just left that as is. – Uroš Milošević Feb 09 '23 at 15:59
  • Alright, that makes sense. So, is there a way to include Docker Compose file in image? And how should they run it if it can be included? @AymDev – Uroš Milošević Feb 09 '23 at 16:01
  • Okay, maybe Debian can run APK commands, seems weird to me but I'm not the most experienced about that. – AymDev Feb 09 '23 at 16:04
  • You should not include the docker-compose.yml into the image, but you should include it in your Git repository. If someone clones your repository he would only have to do `docker compose up -d` and it will build the image the first time. – AymDev Feb 09 '23 at 16:06
  • Oh, if I understood you well. When I push the docker-compose file to my Git repository and I clone my Git repo with all source files including docker-compose, it can be run? @AymDev – Uroš Milošević Feb 09 '23 at 16:10
  • Exactly ! I looked in my public repos, I always provide a **Dockerfile**, a **docker-compose.yml** and a **Makefile** to make things even easier: [here](https://github.com/AymDev/Fregata-demo) and [there](https://github.com/AymDev/FregataBundle). – AymDev Feb 09 '23 at 16:14

0 Answers0