Docker Community Forums

Share and learn in the Docker community.

Use sockets for communication between 2 containers

(Alexfatyeev) #1

Hello everybody.
I’m trying to find an easy way to deploy php application to remote Docker Host.

I have 2 Docker containers: App & Web.

App — simple container with php application code. It is used only for storage and deliver the static code/data to the remote Docker host.

App image Dockerfile:

FROM debian:jessie
COPY . /var/www/app/
VOLUME ["/var/www/app"]
CMD ["true"]

Web — web service container, consist of PHP-FPM + Nginx.

Web image Dockerfile:

FROM nginx

# Remove default nginx configs.
RUN rm -f /etc/nginx/conf.d/*

# Install packages
RUN apt-get update && apt-get install -my \
  supervisor \
  curl \
  wget \
  php5-cli \
  php5-curl \
  php5-fpm \
  php5-gd \
  php5-memcached \
  php5-mysql \
  php5-mcrypt \
  php5-sqlite \
  php5-xdebug \

# Ensure that PHP5 FPM is run as root.
RUN sed -i "s/user = www-data/user = root/" /etc/php5/fpm/pool.d/www.conf
RUN sed -i "s/group = www-data/group = root/" /etc/php5/fpm/pool.d/www.conf

# Pass all docker environment
RUN sed -i '/^;clear_env = no/s/^;//' /etc/php5/fpm/pool.d/www.conf

# Add configuration files
COPY config/nginx.conf          /etc/nginx/
COPY config/default.vhost        /etc/nginx/conf.d
COPY config/supervisord.conf    /etc/supervisor/conf.d/
COPY config/php.ini             /etc/php5/fpm/conf.d/40-custom.ini

VOLUME ["/var/www", "/var/log"]

EXPOSE 80 443 9000

I want to access data/code from App container by Web-services container. Using volumes or named volumes for share code between containers is not a good idea because it lost the ability to quickly upgrade to the new version of deployed code/data.
People from the Docker team advised to use sockets for this purpose. But I could not find anything about communications between containers by socket in the official documentation.

Any ideas about data/code access in App container from Web container by socket?

Thank you very much for your help and support!