Search code examples
phpdockernginxamazon-ecs

Can I access the filesystem of a running NGINX container instance?


Quick summary: I have a single ECS task definition that spins up an NGINX (latest) instance and a PHP (php:7-fpm) instance. I have set up seperate volumes for a site.conf file as well as the PHP project I want NGINX to serve.

The ECS service starts this task without problem. The source code I have been given is in a "wrapper" folder. We'll call it "wrap" for now. Inside "wrap" are some config files, various other php files and another folder called public. Inside public is the index.php.

My site.conf file looks like so:

server {
root /wrap/public;
listen 80;
index index.php;
server_name localhost;
error_log  /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;


location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

My ECS task definition mountpoints look like so:

mountPoints: [
    {
      "containerPath": "/etc/nginx/conf.d/",
      "sourceVolume": "config",
      "readOnly": false
    },
    {
      "containerPath": "/usr/local/nginx/",
      "sourceVolume": "webdata",
      "readOnly": false
    }
 ]

The ECS task definition volumes are such:

"volumes": [
{
  "host": {
    "sourcePath": "/ecs/config"
  },
  "name": "config"
},
{
  "host": {
    "sourcePath": "/ecs/webdata"
  },
  "name": "webdata"
},
{
  "host": {
    "sourcePath": "/ecs/debug"
  },
  "name": "debug"
}

],

The webdata folder on the ECS host holds the "wrap" folder.

Something is wrong because NGINX keeps giving me a 404 error. I have tried to run Docker attach on the NGINX container, however - I am not sure what process I am attaching to on the container. I CANNOT run LS, or PWD or any command - I am assuming it's just a STDout process?

How can I attach to the running NGINX instance to see the filesystem to debug my issue? Or, is there something in my post that pops out at anyone?

TIA!


Solution

  • you can execute

    docker exec -it $instance_name /bin/bash
    

    use docker ps to find the instance name