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 am I supposed to use a Postgresql docker image/container?
  • Docker do not work from build remotely at Jenkins slave. What' the reason?
  • Issue withDocker Selenium Grid on VM
  • Jenkins docker plugin and linked slaves
  • Docker communication between two container with Java
  • Migrating Established TCP connection with docker containers
  • Jenkins and docker-compose
  • Set $PROJECT_NAME in docker-compose file?
  • Dokku installation fails
  • How to pass parameters to a .net core project with dockerfile
  • docker: how to get veth bridge interface pair easily?
  • docker logs and buffered output
  • 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.