Docker – Access linked Container

I am currently trying to learn some docker.
As of now I have made wordpress with php and nginx running.

My Dockerfiles are pretty hard coded, they won’t work out of the box without their configs.

  • Docker: kill/stop/restart a container, parameters maintained?
  • Robot Framework and CI, run in container or not
  • Cannot get a valid response from Docker Registry remote API
  • docker api ContainerExecInspect cannot get correct exit code
  • how to setup a docker image on Arukas.io?
  • Build Visual Studio C++ project in docker
  • So what I am trying to do now is remove all of my volumes and use environment variables to provide the information I need to build my needed configuration files, but I am struggling with the linking of containers.

    I want to use a *.sh file as an Entrypoint to set the values I need within my configs. That’s is kind of easy and working by now.

    My Problem now is that I need to access a linked containers file system (to replace the volumes I used).

    I have a app.conf file (don’t blame it, I did’nt care for best practices or anything by now):

        server {
            listen          0.0.0.0:80;
    
            server_name     _;
            root            LINKEDADRESS/ROOT_DIR;
            index           index.php index.html index.htm;
            access_log /var/log/nginx/default_access.log;
            error_log /var/log/nginx/default_error.log;
    
           # Pass PHP scripts to PHP-FPM
           location ~* \.php$ {
           fastcgi_index   index.php;
           fastcgi_pass    unix:LINKEDADRESS/RUND_DIR/php7-fpm.sock;
           include         fastcgi_params;
           fastcgi_param   SCRIPT_FILENAME    LINKEDADRESS/ROOT_DIR$fastcgi_script_name;
           }
        }
    

    The linked container is my php/wordpress container.
    My nginx-server need to access it’s filesystem to get wordpress visible in the browser. Setting the ROOT_DIR as a env-variable isn’t that big of a deal, but I don’t know how to get the adress of the linked container to access the files.

    I know that linking container causes the creation of some env-variables like

    XZW_PORT

    XZW_TCP_ADRESS

    etc.pp.,
    but they seem to depend on the linked containers name. So, do I need to get that name from anywhere (maybe another env-variable) or is there a easier solution I didn’t think about?

    I’ve just started using docker that deep (I’ve made very simpel Dockerfiles before, but that’s totally different), so I will appreciate any explanations I get.
    I tried to show my way of thougts til now, I hope it’s not to hard to read.
    Thanks!

    EDIT: I’ve just came across globs within bash-scripts, but I find them a bit confusing.

    echo "${!X*}
    

    gives me every environment variable beginning with X, but how do I get all of the variables (which is hopefully only one) ending with _PORT? I don’t get it.

  • Create dynamic environment variables at build time in Docker
  • Kubernetes multinode setup cannot remove docker0 interface
  • Docker Compose In Production
  • How to prevent docker images on docker hub being overwritten
  • Dockerfile/npm: create a sudo user to run npm install
  • Dockerfile COPY / ADD fails for file in build context
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.