1

I know about the laradock, but i need to pass all the steps for myself.

i gonna learn Laravel and the same time recently i have opened for myself docker :)

now i need to join alltogether:
docker-compose with images:
- php:7.2.2-apache
- mariadb
- phpmyadmin/phpmyadmin
- and some how composer

laravel will be on my host outside containers.

so far i have made my own image "web_server" from the php:7.2.2-apache image and run inside mod_rewrite

FROM php:7.2.2-apache

RUN apt update && apt install mc -y && apt install composer -y  
RUN a2enmod rewrite

my docker-compose.yml looks like

version: '3'

services:
  db:
    image: mariadb
    volumes:
      - ./db:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: "secretpswd"
      MYSQL_DATABASE: "test_db"
      MYSQL_USER: "my_user"
      MYSQL_PASSWORD: "secretpswd"
    ports:
      - "3306:3306"

  web:
    image: web_server
    container_name: php_web
    depends_on:
      - db
    volumes:
      - ./www:/var/www/html/
    ports:
      - "80:80"
    stdin_open: true
    tty: true

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: pma
    depends_on:
      - web
      - db
    environment:
     PMA_HOST: "db"
     PMA_PORT: 3306
     PMA_ARBITRARY: 1
    restart: always
    ports:
     - 8080:80
    volumes:
     - ./sessions:/sessions

now i have to install composer ...
i have two choices

  1. use composer/composer image from the docker hub in this case i have no idea how it will be used by laravel and with laravel because laravel will be under the control of separate web container
  2. install composer inside the web_server image which is made from
    the php:7.2.2-apache image

i have tried but start receiving errors

The following packages have unmet dependencies:
composer : Depends: php-symfony-console (>= 2.5) but it is not installable
Depends: php-symfony-filesystem (>= 2.5) but it is not installable
Depends: php-symfony-finder (>= 2.4) but it is not installable
Depends: php-symfony-process (>= 2.4) but it is not installable
Depends: php-cli
Depends: php-common but it is not installable
Depends: php-json-schema but it is not installable
Depends: php-composer-ca-bundle (>= 1.0) but it is not installable
Depends: php-composer-ca-bundle (< 2~~) but it is not installable
Depends: php-composer-semver (>= 1.0) but it is not installable
Depends: php-composer-semver (< 2~~) but it is not installable
Depends: php-composer-spdx-licenses (>= 1.0) but it is not installable
Depends: php-composer-spdx-licenses (< 2~~) but it is not installable
Depends: jsonlint (>= 1.4) but it is not going to be installed
Depends: jsonlint (< 2~~) but it is not going to be installed
Depends: php-cli-prompt (>= 1.0) but it is not installable
Depends: php-cli-prompt (< 2~~) but it is not installable
Depends: php-psr-log (>= 1.0) but it is not installable
Depends: php-psr-log (< 2~~) but it is not installable
Recommends: git but it is not going to be installed E: Unable to correct problems, you have held broken packages. The command '/bin/sh -c apt update && apt install mc -y && apt install composer -y' returned a non-zero code: 100

so it's time to ask for help.

  1. which way should i use?

  2. in case of separate composer/composer container how to use it inside web_server container and how laravel will use it

  3. in case of the composer installation inside php:7.2.2-apache image how to solve those errors

1 Answer 1

2

I think best option is to make a separate docker container for composer. so that you don't have composer mixed with your php apache container.

you can add the following lines to your docker-compose file:

composer:
    restart: 'no'
    container_name:composer
    image: composer:latest
    working_dir: /var/www/html
    command: composer install -d /var/www/html
    volumes:
    - ./www:/var/www/html/

the volume is being synced in the composer container and in your php container so the vendor folder will also be synced between the two containers.

the restart: no option is there so that when you run docker-compose up the composer container is only being started once, when it is done it is being stopped.

To run composer install you can use: docker-compose run composer composer install

You can also use the command on the next line, so that composer install is a little bit faster.

(more information about the package: https://github.com/hirak/prestissimo)

command: >
      bash -c "composer global require hirak/prestissimo && composer install -d /var/www/html"
Sign up to request clarification or add additional context in comments.

6 Comments

ty for the answer. i have 2 questions: 1) prestissimo need to be executed to create my own image from the composer/composer image ? 2) in case of the separate composer container through which container should i run laravel command line tools through the composer based container or through the web_server container ? for example docker-compose exec CONTAINER_NAME php artisan key:generate
1). prestissimo does not need to execute from your own image, it can be as long as composer is installed on the container your running it. 2). all laravel commands (key:generate) can still run from the web_server container.
thanks for your answers. i dont have composer container started. happen smth out of my understanding :) so i have changed docker-compose.yml, when i run it for the first time Creating composer ... done, after that i dont have composer container started. then i run second time docker-compose and receive Starting composer ... done but still no container with composer started ... smth is wrong or i just do not know how to use that container ?
ok i reread composer/composer description on docker hub and have created separate sh script which uses composer image ... but this is kind of partially ruine the concept of containers, right ? to keep host machine without any installations, with the same success i could install composer nativelly to the host ...
docker-compose up -d
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.