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 ?

  • Getting Internet connection inside Docker containers inside an VM behind a corporate firewall
  • How to connect external mysql server in docker container
  • How to execute a command from the host when it's on the $PATH?
  • Can't pull image from docker registry when docker is pointing to a swarm
  • Pass argument to docker compose
  • How to set UIDs for official Docker images?
  • Backup/Restore a dockerized PostgreSQL database
  • How to remount the proc filesystem in a docker as a r/w system?
  • Docker, docker-compose, networking: how to configure?
  • Not able to pull image from local docker registry when tried to create a POD using yaml file
  • Rancher imageUuid not Unique
  • Can't return list of docker repository images through API
  • 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.