3

I've project that uses memcached. So when docker trying to "pip install pylibmc", library can't find libmemcached cause it's not installed yet. How can I organise my docker-compose.yml, or maybe I have to do something with dockerfile?

Now my docker-compose.yml looks like (I've deleted memcached container lines):

version: '2'
    services:

      app:
        build: .
        volumes:
          - ./app:/usr/src/app
          - ./logs:/var/log
        expose:
          - "8000"
        links:
          - db:db
        networks:
          tickets-api:
            ipv4_address: 172.25.0.100
        extra_hosts:
          - "db:172.25.0.102"

      webserver:
        image: nginx:latest
        links:
          - app
          - db
        volumes_from:
          - app
        volumes:
          - ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
          - ./nginx/uwsgi_params:/etc/nginx/uwsgi_params
        ports:
          - "80:80"
        networks:
          tickets-api:
            ipv4_address: 172.25.0.101

      db:
        restart: always
        image: postgres
        volumes:
          - ./postgresql/pgdata:/pgdata
        ports:
          - "5432:5432"
        environment:
          - POSTGRES_USER=postgres
          - POSTGRES_PASSWORD=postgres
          - PGDATA=/pgdata
        networks:
          tickets-api:
            ipv4_address: 172.25.0.102

    networks:
      tickets-api:
        driver: bridge
        ipam:
          config:
          - subnet: 172.25.0.0/24
  • are you app, an php app ? – levi Sep 16 '16 at 00:36
  • It's a python app. You might want to post more about the error you received. the exit error message and some context log would be great. I added an answer from my experience installing similar packages. – dnephin Sep 17 '16 at 15:32

2 Answers2

2

You have two options. Installing it within your app container or install memcached as isolated container.

OPTION 1

You can add a command to install libmemcached on your app's Dockerfile.

If you are using some kind of ubuntu based image or alpine

Just add

RUN apt-get update && apt-get install -y \
        libmemcached11 \
        libmemcachedutil2 \
        libmemcached-dev \
        libz-dev

Then, you can do pip install pylibmc

OPTION 2

You can add memcached as a separated container. Just add in your docker-compose

memcached:
  image: memcached
  ports:
    - "11211:11211"

Of course, you need to link your app container with memcached container.

levi
  • 22,001
  • 7
  • 73
  • 74
1

The easiest way to solve this problem is to update the Dockerfile for the app and install the development dependencies required to build the python package.

On ubuntu/debian that might be something like:

apt-get install libmemcached-dev gcc python-dev

A second (more advantaged) option is to build a wheel for this package in a separate container, then install the wheel instead of the source tarball. That way you don't have to install any other packages, and your final image will be much smaller. However it requires more work to setup.

dnephin
  • 25,944
  • 9
  • 55
  • 45