Hey everyone! I'm a developer looking to tidy up my workspace, and I want to create a Docker Compose setup that includes all the command-line tools I need. My goal is to run everything in separate containers but still have their binary files accessible through /usr/local/bin, so it feels like they're installed directly on my host machine.
However, I'm running into an issue when trying to bind the binary files. For instance, I'm getting this error: `Error response from daemon: failed to create task for container... not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)?`
Here's a snippet of my Docker Compose configuration for the AWS CLI service:
```yaml
services:
aws-cli:
image: public.ecr.aws/aws-cli/aws-cli:2.28.19
restart: unless-stopped
volumes:
- ~/.aws:/root/.aws:ro
- /usr/local/bin/aws:./usr/local/bin/aws
entrypoint: ["/bin/bash", "-c", "while true; do sleep 1000; done"]
```
Could anyone help me figure out where I'm going wrong?
3 Answers
If you're using Visual Studio Code, there's a handy plugin called Dev Containers that might help you edit within the Docker environment more seamlessly. Many other editors have similar features, so check your IDE's plugins for this functionality!
A straightforward approach could be to simply run an Ubuntu or Debian image where you can easily install your CLI tools. As for keeping the container alive, consider using `tail -f /dev/null` instead of a sleep command.
Add this to your Dockerfile for installing AWS CLI and other tools:
```bash
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
&& unzip awscliv2.zip
&& ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
```
Honestly, I’d recommend just using dev containers for this. They have built-in support and often make the whole process much easier. Don’t reinvent the wheel—most IDEs today are designed to work with them directly!
Right? It's much simpler to rely on existing tools than to create your own solutions which could lead to more complexity!