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.

  • Hyperledger Fabric Set Up Docker-Compose Key Error
  • Google Kubernetes storage in EC2
  • Assign public IP to docker
  • How to forward hostname based request to a specific docker container
  • How to get the mapped port on host from a docker container?
  • Does docker CMD carry on from upper images to be passed as argument to ENTRYPOINT
  • 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.

  • Re-introduced “Unknown initial character set index” error?
  • Kubernetes replication controller in CrashLoopBackOff state
  • Docker -v issue
  • Launch two nodejs app inside Docker container using pm2
  • Cross-Host Communication: Ambassador pattern versus port exposition
  • Why is /etc/hosts file empty in my docker container?
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.