Running package manager inside the docker

I’ve built an image for the purpose of PHP development, and it became clear to me that I didn’t really thought about how to access the tools that I need for every day development. For example: composer, package manager for PHP, I need it to run whenever composer.json updates. I thought it is worth installing those tools inside the same image, but then I don’t have a way to access them. So, I can:

  1. Create separate image for composer and run it in different container
  2. Install composer on my host machine.

I’d like to avoid option 2), but then, does it have sense having a setup like 1) ? How did you guys solved this issue ?

  • How to integrate spark cluster with other Hadoop2.x cluster on Docker
  • Permission denied in custom buildpack
  • When I use PyCharm and odoo, [Errno 2] No such file or directory Process finished with exit code 2
  • Docker caching for travis builds
  • Percona 5.6 Docker Image cannot load my /etc/mysql/conf.d/*.cnf
  • Docker volume content does not persist
  • Docker with different gateways on containers
  • Standalone kubelet persistent disk mount on Google Cloud instance
  • How to use multiple base images with Docker?
  • Restart CMD process within cronjob
  • How to run headless browser testing in docker container
  • Issue running Gulp on Docker
  • One Solution collect form web for “Running package manager inside the docker”

    Unless you have some quite specific requirements there is a third option:

    Connect to the container using docker exec command:

    docker exec -it CONTAINER-NAME/ID COMMAND [ARG...]
    

    Here is the example:

    1: Create your application:

    echo "<?php phpinfo();" > index.php
    

    2: Start container:

    docker run -it --rm --name my-apache-php-app -p 80:80 -v "$PWD":/var/www/html php:5.6-apache
    

    3: Open another terminal window and exec required commands inside running container:

    docker exec -it my-apache-php-app curl -sS https://getcomposer.org/installer | php
    docker exec -it my-apache-php-app ls
    

    If you need shell inside running container – run:

    docker exec -it my-apache-php-app bash
    

    That’s it!

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.