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 ?

  • Docker: How to use selenium server to do nightwatchJS test?
  • Docker Container Shell Tab Hell [duplicate]
  • Stopping paused Docker containers
  • docker issue with namespaces - Container ID 110090219 cannot be mapped to a host ID
  • docker mysql persistent storage
  • How do I run a docker container as a privileged user with user namespaces
  • Docker stats from java
  • Docker Compose CLI Flags
  • How do I expose a UDP Port on Docker?
  • Using a docker container querying an AWS RDS Instance
  • Why does Docker fail to open nginx.conf when I try to mount a volume?
  • Docker mysql image - move internal container DB to the volume
  • 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 | 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.