3

I use a pretty easy docker setup that includes docker-compose and docker-sync. I have the following files:

docker-compose-dev.yml

version: "2"
services:
  apache:
    volumes:
      - ./docker-config/vhost:/etc/apache2/sites-enabled/000-default.conf
      - rr-sync:/var/www/html:nocopy # nocopy is important

volumes:
  rr-sync:
    external: true

docker-compose.yml

version: '2'
services:
  apache:
    image: bylexus/apache-php7
    ports:
      - 80:80

  db:
    image: orchardup/mysql
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: rr

docker-sync.yml

version: "2"

options:
  verbose: true
syncs:
  rr-sync: # tip: add -sync and you keep consistent names as a convention
    src: './src'
    sync_excludes: ['.git']

The image that I use is bylexus/apache-php7 and it has no support for curl nor I have a tool like vim installed in the container.

The question is, how can I install curl and vim but keep using this image for apache? What do I need to change in the files above?

Thanks.

2 Answers 2

10

Add your own Dockerfile to the project that builds on your desired base image. In this file, add your own packages (for example, curl and vim):

FROM bylexus/apache-php7

RUN apt-get install -y curl vim

Then, in your docker-compose.yml file, do not use the image property, but the build property, instead:

version: '2'
services:
  apache:
    build: .
    ports:
      - 80:80


Disclaimer: Of course, the precise method for adding new packages is dependent on the base image. For example, the bylexus/apache-php7 image in this case is built on the ubuntu:16.10 image (as can be seen in the respective Dockerfile), so you can use Ubuntu's package management tools. Images other than the bylexus/apache-php7 one might use other base distributions with other package managers).

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks - do I need to reference the Dockerfile anywhere?
Only if it's not named Dockerfile. I'll add a link to the respective section of the reference.
Thanks. Does this do anything else to the container? Because after changing it, the front page is doing fine, but all links - like localhost/backend result in an 404.
0

You can do one of two things:

  1. Build your open image that installs these tools:

FROM bylexus/apache-php7

RUN apt-get update && \
    apt-get dist-upgrade -y && \
    apt-get install -y \
      curl \
      vim

The you build this image and use it inside the composefile

  1. Manually install these tools inside the container after it starts up.

docker-compose exec apache bash

And then install the tools that you want. Note in this case you will need to do that again if you remove the container and then create (you can use volumes to mitigate this however the executables are soft linked from say /usr/bin/vim to other dirs, so you will have to use volume for each one of these directories containing the executable links or redirect the links directly...)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.