Help us understand the problem. What is going on with this article?

Docker PHP memcached追加

DockerのPHPでmemcachedを利用できるようにする方法

構成

---docker
|--docker-compose.yml
|--docker
   |--nginx
   |    |--nginx.conf
   |
   |--phpfpm
   |    |--Dockerfile
   |    |--php.ini
   |
   |--memcached
        |--Dockerfile

docker-compose.yml

version: '3'

services:
  memcached:
    container_name: memcached
    build: ./docker/memcached
    #image: memcached:latest
    ports:
        - 11211:11211

  nginx:
    container_name: nginx
    build: ./docker/nginx
    #image: nginx:alpine
    restart: always
    ports:
        - 80:80
    volumes:
        - ./docker/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
        - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
        - ./volumes/nginx/:/var/log/nginx
    depends_on:
        - phpfpm

  phpfpm:
    container_name: phpfpm
    build: ./docker/phpfpm
    #image: php:7.3-fpm-alpine
    restart: always
    volumes:
        - ./volumes/www/html:/var/www/html
        - ./docker/phpfpm/php.ini:/usr/local/etc/php/php.ini
        - ./docker/phpfpm/php-fpm.conf:/usr/local/etc/php-fpm.conf

phpfpm/Dockerfile

FROM php:7.3-fpm-alpine

RUN apk update \
&& apk add \
    autoconf \
    libmemcached-dev \
    zlib-dev \
    gcc \
    g++ \
    make \
&& pecl install memcached

phpfpm/php.ini

extension=memcached.so

memcached/Dockerfile

FROM memcached:latest

/volumes/www/html/index.php

<?php

//phpinfo();exit;
$results = array();
$mc = new Memcached();

"memcached"はdocker-compose.ymlのcontainer_nameを指定する
$mc->addServer("memcached", 11211);
$mc->set("test1", "hoge");
$mc->get("test1");

?>
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away