Skip to content
This repository has been archived by the owner on Mar 13, 2019. It is now read-only.

How could I make composer container execute in a other container? #88

Closed
meotimdihia opened this issue Jun 27, 2016 · 8 comments
Closed

Comments

@meotimdihia
Copy link

From https://hub.docker.com/r/composer/composer/

akosgluebe said (3 months ago)
Hello,

It is shown how to make an alias: "Now the composer command is available native on host". Great.
How could I make this alias/this command available in a running container? Lets say I start up, for example, the latest jenkins container (or whatever other container), how could I use this composer inside that container? (I would like to avoid docker in docker)
Thanks!

i have same his question, can we run this in a other container ?
i see this problem a long time ago but can't think any simple resolution.

Anyone may suggest for me, thx :)

@RobLoach
Copy link
Owner

Do you have either a Dockerfile or docker-compose.yml that you could send over to test? The idea is here is that you mount the volumes across the containers, and then run Composer through the Composer container.

@meotimdihia
Copy link
Author

meotimdihia commented Jun 28, 2016

I am using this docker-compose.yml:

version: '2'
services:
    php-fpm:
        build:
            context: ./php-fpm
        image: plf_php-fpm:5.6
        links:
            - mysql:mysql
            - redis:redis
        environment:
            - MYSQL_HOST=mysql
            - MYSQL_USER=platform-admin
            - MYSQL_PASSWORD=platform123
            - MYSQL_DATABASE=platform
            - REDIS_HOST=redis            
        depends_on:
            - redis
            - mysql
        volumes:
            - ../src/:/var/www/html/
            - ./php-fpm/www.conf:/usr/local/etc/php-fpm.d/www.conf
    nginx:
        image: nginx:1.7.10
        ports:
            - 8080:80
        links:
            - php-fpm:php-fpm
        volumes_from:
            - php-fpm
        volumes:
            - ./nginx/conf.d/:/etc/nginx/conf.d/
        depends_on:
            - php-fpm
    mysql:
        build:
            context: ./mysql
        image: meotimdihia/plf_mysql:5.7
        volumes:
            - ./mysql/data:/var/lib/mysql
            - ./mysql/import/dump.sql:/tmp/dump.sql
        environment:
            - MYSQL_ROOT_PASSWORD=admin
            - MYSQL_USER=platform-admin
            - MYSQL_PASSWORD=platform123
            - MYSQL_DATABASE=platform
    redis:
        image: redis:3-alpine
    jenkins:
        image: jenkins:2.3
        ports:
            - 8060:8080
            - 50000:50000
        volumes:
            - ./jenkins/home:/var/jenkins_home
            - ../src/:/var/www/html/

My workflow is like this:

  • Push my code to github repository
  • Github webhook request to my Jenkins container URL
  • Jenkins container pull github repository
    -run Composer install at here .
  • Build test and deploy code

But how to execute composer install container here ?
Now i recognize this problem should be at docker groups. But if you can suggest me , its a big help. :)

@RobLoach
Copy link
Owner

  1. Add a Composer service, mounting the volumes:

    composer:
        image: composer/composer
        volumes_from: php-fpm
        working_dir: /var/www/html
  2. Run Composer through docker-compose:

    docker-compose run composer install
    

@meotimdihia
Copy link
Author

We can run docker-composer on host machine , but i wonder we can execute composer install in Jenkins container , because i need to execute automatically composer install.

In real my case i am trying to setup on kubernetes (google container engine) and docker-compose on localhost.

@RobLoach
Copy link
Owner

Another solution is to change the entrypoint and command and make your own script to run Composer install when the service starts.

@meotimdihia
Copy link
Author

thx for your answer, after some research in docker's documention, i see docker remote API :
https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/exec-create
And
kubernetes API :
http://kubernetes.io/kubernetes/third_party/swagger-ui/#!/api%2Fv1/connectPostNamespacedPodExec

i will try to follow this direction: Jenkin's container will call remote API to execute a command in Composer's container.

I close this issue, thank you once again.

@delmicio
Copy link

delmicio commented Jun 2, 2017

@RobLoach I've been trying the past two days to include auto composer commands in my docker-compose file and failing.
Could you share with us your solution if you have got one.

version: "3"

services:
  composer:
    image: composer/composer:php5-alpine
    volumes:
      - ./app/:/app
    command: ["install --ignore-platform-reqs", "dump-autoload --optimize"]

@harriswong
Copy link

@delmicio

  1. Make sure your /app folder has a composer.json.
  2. Try the working_dir as per How could I make composer container execute in a other container? #88 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants