skip to Main Content

I want to start two docker-compose services of memcached. I am using the docker standard memcached image for both instances. Memcached should be able to use environment variables to change the port it is listening on, but it does not seem to work.

My docker-compose.yml

...
memcached-server:
    image: memcached
    environment:
      MEMCACHED_PORT: 11211
    ports:
      - 11311:11211
    networks:
      - my_net

memcached-server-lock:
    image: memcached
    environment:
      MEMCACHED_PORT: 11212
      MEMCACHED_CACHE_SIZE: 128
    ports:
      - 11312:11212
    networks:
      - my_net
...

The containers are starting correctly but the env variables do not seem to be picked up:

0ae76227b72b        memcached                            "docker-entrypoint..."   17 seconds ago      Up 13 seconds       0.0.0.0:11311->11211/tcp mobidesk_memcached-server_1
ab3682361dad        memcached                            "docker-entrypoint..."   17 seconds ago      Up 12 seconds       11211/tcp, 0.0.0.0:11312->11212/tcp  mobidesk_memcached-server-lock_1

Does anybody know which variables to use. Or is it something else I missed?

2

Answers


  1. You don’t need to change the docker port used by memcache, you can simply have it like this:

    memcached-server:
        image: memcached
        ports:
          - 11311:11211
        networks:
          - my_net
    
    memcached-server-lock:
        image: memcached
        environment:
          MEMCACHED_CACHE_SIZE: 128
        ports:
          - 11312:11211
        networks:
          - my_net
    

    Anyway the variables you’re using are ok. You shouldn’t use ports different from the ones EXPOSEd by the Dockerfile.

    Login or Signup to reply.
  2. Actually, you don’t need to edit the .sh file. Is enough to use the “command” option directly in docker compose:

      cache:
        image: memcached:latest
        command:
          - '-m 128'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search