Need help Docker AWS EC2 docker compose

I updated the SSL certs but now I am unable to docker compose stack (bring stack down and back up)

when i run docker-compose down

[root@ip-172-31-44-19 docker]# docker-compose down
Can’t find a suitable configuration file in this directory or any
parent. Are you in the right directory?

    Supported filenames: docker-compose.yml, docker-compose.yaml

[root@ip-172-31-44-19 docker]#

Looks like you are not in the folder where you compose file is located.

if your docker compose version is recent enough, there is a chance to get the file location from one of the containers of the compose deployment:

docker inspect {container name or id} --format '{{index .Config.Labels "com.docker.compose.project.config_files"}}'

Make sure to replace the placeholder {container name or id} with a real value.

If it doesn’t return the path to the compose file, then you can check if any other label provides a meaningful hint:

docker inspect {container name or id} --format '{{json .Config.Labels }}' | jq

if jq does not exist on your host, remove the | jq part and re-run the command without it.

Just adding another idea I would mention that Docker Compose v2 supports compose.yml in addition to docker-compose.yml. If you named the compose file like that, Docker Compose v1 will not find it. IF Docker Compose v2 is available in the EC2 instance, you can try

docker compose down

instead of

docker-compose down

In fact, if you have Docker Compose v2 and you are also in a wroong directory, you can use

docker compose ls

to list the compose files that is known by Docker Compose v2. It is based on the same label that @meyay mentioned so that is a perfectly good solution too and even better than docker compose ls if you know exactly which container you are interested in.

1 Like

I was not aware this feature exists. I felt such a feature was long time missing, or even better something that allows parity with how it works in docker swarm, where the compose file is not needed to remove a stack.

For some reason, none of the docker commands are working and I keep getting the same error. I’m running my setup on AWS EC2. I updated SSL certs, there are 3 containers one of which is ngnix and I just needed to docker-compose stack (bring stack down and back up) then restart but no method is working thus far.

Thanks. I tried this method and still wrong directory error; is there a command to locate the correct directory where the docker-compose file is? I thought I located it already but when I ran docker commands, it didn’t work.

Please share the output for the above asked commands (including the command) + the output of docker ps -a so we see hat containers are running on the host and which container you try to inspect, and what labels it has - if it’s a compose deployment it should have labels.

Below I have shared the output for the above asked commands

[root@ip-172-31-44-19 ~]# docker ps -a
db20f155bc33 docker_shuffleme_nginx “/docker-entrypoint.…” 17 months ago Up 17 months>80/tcp,>443/tcp docker_shuffleme_nginx_1
6701f3103c7a docker_shuffleme_restservice “/app/rest-entrypoin…” 17 months ago Up 17 months>8000/tcp docker_shuffleme_restservice_1
676b42175394 docker_shuffleme_gui “docker-entrypoint.s…” 17 months ago Exited (0) 17 months ago docker_shuffleme_gui_1
eb42a91ccc5d mariadb:latest “docker-entrypoint.s…” 17 months ago Up 17 months 3306/tcp shuffleme_mariadb
[root@ip-172-31-44-19 ~]# cd /app/ShuffleMe/website/docker/
[root@ip-172-31-44-19 docker]# ls -al
total 40
drwxrwxr-x 2 ec2-user ec2-user 260 Jul 21 2021 .
drwxrwxr-x 10 ec2-user ec2-user 4096 Aug 31 2021 …
-rw-rw-r-- 1 ec2-user ec2-user 1763 Jul 21 2021 docker-compose-beta.yml
-rw-rw-r-- 1 ec2-user ec2-user 1760 Jul 21 2021 docker-compose-dev.yml
-rw-rw-r-- 1 ec2-user ec2-user 1783 Jul 21 2021 docker-compose-local.yml
-rw-rw-r-- 1 ec2-user ec2-user 1017 May 28 2021 dockerfile-python-tests
-rw-rw-r-- 1 ec2-user ec2-user 359 May 28 2021 dockerfile-python-tests.dockerignore
-rw-rw-r-- 1 ec2-user ec2-user 364 May 28 2021 dockerfile-react-test
-rw-r–r-- 1 ec2-user ec2-user 941 Jul 11 2021 .env
-rwxrwxr-x 1 ec2-user ec2-user 109 May 28 2021 makemigrations
-rwxrwxr-x 1 ec2-user ec2-user 596 May 28 2021 rest-entrypoint
[root@ip-172-31-44-19 docker]# docker inspect {db20f155bc33 d} --format ‘{{index .Config.Labels “com.docker.compose.project.config_files”}}’

Error: No such object: {db20f155bc33
Error: No such object: d}
[root@ip-172-31-44-19 docker]# docker inspect {db20f155bc33} --format ‘{{index .Config.Labels “com.docker.compose.project.config_files”}}’

Error: No such object: {db20f155bc33}
[root@ip-172-31-44-19 docker]# docker compose ls
docker: ‘compose’ is not a docker command.
See ‘docker --help’
[root@ip-172-31-44-19 docker]#

At least you know where the compose files are located.

Since docker compose doesn’t work, it is safe to say the v2 version is not installed.

I notice you ran the command `docker inspect {db20f155bc33} --format ‘{{index .Config.Labels “com.docker.compose.project.config_files”}}’ twice but didn’t follow my exact instructions precisely on both attempts. Please run these commands again and share their output:

docker inspect db20f155bc33  --format ‘{{index .Config.Labels “com.docker.compose.project.config_files”}}’


docker inspect db20f155bc33  --format ‘{{.Config.Labels}}’

Without the information from the labels, it is hard to say which of those compose files are the one being used. It could be one of the or multiple, and it could even be a swarm stack deplyoment (which also uses compose files).

Output run from the commands below:

[root@ip-172-31-44-19 ~]# docker inspect db20f155bc33 --format ‘{{index .Config.Labels “com.docker.compose.project.config_files”}}’
Template parsing error: template: :1: unclosed action
[root@ip-172-31-44-19 ~]# docker inspect db20f155bc33 --format ‘{{.Config.Labels}}’
‘map[com.docker.compose.config-hash:44ab2459ac9564bce41a6ea1aca6d6113de98ad7d7d4dbc6c9f909e60e838d2b com.docker.compose.container-number:1 com.docker.compose.oneoff:False com.docker.compose.project:docker com.docker.compose.project.config_files:docker-compose-beta.yml com.docker.compose.project.working_dir:/app/ShuffleMe/website/docker com.docker.compose.service:shuffleme_nginx com.docker.compose.version:1.29.2 maintainer:NGINX Docker Maintainers]’
[root@ip-172-31-44-19 ~]#

There you go:
inside the folder /app/ShuffleMe/website/docker run docker-compose -f docker-compose-beta.yml down. And to start it again execute: docker-compose -f docker-compose-beta.yml up -d

(post deleted by author)

Now that the SSL certs were replaced, docker compose (brought stack down and back up again); I tried to restart so that the SSL certs would work and received an error:

[root@ip-172-31-44-19 ~]# cd /app/ShuffleMe/website/docker/
[root@ip-172-31-44-19 docker]# sudo service nginx restart
Redirecting to /bin/systemctl restart nginx.service
Failed to restart nginx.service: Unit not found.
[root@ip-172-31-44-19 docker]# systemctl reload nginx
Failed to reload nginx.service: Unit not found.
[root@ip-172-31-44-19 docker]#

Please elaborate how you think all these things relate and why what you do is the way to achieve the objective. I am not really able to make sense of it (yet)l

Since you run your setup on AWS, are you sure that certificates are not issued by AWS Certificate Manger and used in an AWS ALB, which forwards public traffic to your ec2 instance(s)?

In my case, I need to restart ngnix and I am receiving an error to restart. The SSL certs are from Godaddy. Our website is still down and since we performed docker compose, the ngnix must restart, I tried, * systemctl reload nginx and this command did not work either.

So no ALB then. I am not going to ask why someone would do it like that.
Apart from that please let me understand your thoughs that lead to your approach.

Note: If the next answer still provides no context clues. I will have to give up.

This is the first time I am renewing the SSL certs via docker and containers. I am actually unsure of what the right approach should be. I replaced the certs, uploaded new certs to EC2, and brought the stack down and back up, that’s it. Our website is still not working. In this case, what do you think the best approach should be to solve this issue?

Firstly: share the compose file (in a “</> preformated text” block, in the submenu of the gear icon)
Then share the nginx conf if declared as volume.

These are the details we can work with.
Prose descriptions usually don’t help much, unless of course you are an expert…

We can not guess how your setup looks like and every setup can look different. This is why providing context information is important.

submenu of the gear icon? Where is this located? I can send files.