How do I get to the shell of my app that's running with Docker Compose

Viewed 22

I need to edit some files for my Apache Answer app, which is running in Docker Compose on a DigitalOcean Droplet

How do I get to the shell of my app that’s running with this Docker Compose:
version: "3"
services:
answer:
image: apache/answer
ports:
- '80:80'
restart: on-failure
volumes:
- answer-data:/data

volumes:
answer-data:

1 Answers

To access the shell of your app running with Docker Compose v2, you can use the docker compose exec command. Here's how you can do it:

  1. Open your terminal.
  2. Navigate to the directory where your docker-compose.yml file is located.
  3. Run the following command to get a shell inside the answer container:
docker compose exec answer sh

If the container has a shell other than sh, such as bash, you can replace sh with bash:

docker compose exec answer bash

This will open an interactive shell session inside the answer container, allowing you to interact with your app.

@chatgpt-4o Command 'docker-compose' not found

Updated answer

Edited the answer to consolidate