Docker-compose commands in yml not working - docker

I am new to docker and am trying to get a few containers up and running using a docker-compose.yml file. But when i run the following command inside the cocker toolbox cli
docker-compose.yml up
I get the following errors:
As you can see, if I run the command
docker-compose -v
I get the version and build info which means it has been installed.
I have googled a lot but failed to find any solution. Kindly suggest.
Thanks in advance

You're trying to run the .yml file. Compose doesn't work like that.
Just run: docker-compose in the directory where docker-compose.yml resides. Docker-compose will automatically find the file.

You tried to run a yml file (which at best, bash interprets as a script). You need to run docker-compose, not docker-compose.yml. The latter is the input config file to the former.
docker-compose config

Related

docker-compose only works if yml file in home directory

For some reason, on Ubuntu 20.04 docker-compose up only works if my docker compose yaml file is in the user's home directory.
I've uninstalled docker, installed it with snap, installed with apt and no difference.
Why is this? I've never seen this on any other server and for some reason this happens here.
How do I fix this so I can run docker-compose from a directory containing a docker-compose.yml file and have it read the pwd?
I have tried the -f option and it does not help.

Does it matter if the docker compose file is named docker-compose.yml or compose.yml?

Looking at examples for docker compose files I found some named "compose.y(a)ml" instead of "docker compose.yml" or "docker-compose.yml" that I've seen. Does it matter if it's "compose." or "docker composer"?
Awesome Compose repo
I've tried to search for an answer online and tried reading on the docker documentation here but didn't figure it out.
https://docs.docker.com/compose/reference/
Thank you
If the file is named exactly docker-compose.yml, running docker-compose with no other options will find it. Otherwise, you must pass a docker-compose -f option with the alternate name, for every docker-compose command.
Style-wise, I'd recommend putting a file named exactly docker-compose.yml (and possibly a matching docker-compose.override.yml with developer-oriented settings) in your repository's root directory. If you're building a custom image, also put the Dockerfile (again, with exactly that name and capitalization) in the repository root directory.

How do I mount a single file in docker-compose

I have a project that need to mount a single directory into the docker container, and I mount it in a similar way
agent:
    image: agent:latest
    container_name: agent
    volumes:
      - $PWD/status.txt:/status.txt
Is A Directory error occurs when I modify status.txt in open mode.
with open('status.txt','a') as f:
...
...
docker-compose seems to recognize files as directories.
I would appreciate it if you could tell me how to solve it?
I can mount files just fine using the same syntax, although I use a relative path, e.g.:
volumes:
- ./sourcedir/file.txt:/target/dir/mountedfile.txt
Where mountedfile.txt is essentially file.txt. There must be something else in your environment causing this issue. To troubleshoot, there are a couple of things you could do, including:
Get a shell into the container and run stat on the target file, e.g. stat mountedfile.txt. That should tell you if it's a file or directory.
Test your configuration manually with plain docker using -v to mount the volumes, e.g.:
docker run --rm -ti -v /sourcedir/file.txt:/target/mountedfile.txt ubuntu:latest bash
Also, there may be some useful information in a (somewhat) unrelated answer.

Run docker-compose on Windows 7

I'm using Docker Toolbox to run docker containers on Windows. When I try to perform docker-compose up Docker cannot find docker-compose.yml. I must cd into container's directory or specify the file path using -f argument. How to get the path?
docker info shows Root Dir as /mtn/sda1/bla/bla which is virtual path and doesn't exist on my PC.
UPD: solved
You may have simply forgot to save the docker-compose.yml. check this first. Try this solution, it worked for me https://github.com/docker/compose/issues/129
hope you get it sorted

How to open/run YML compose file?

How can I open/run a YML compose file on my computer? I've installed Docker for Windows and Docker tools but couldn't figure out how.
If you are asking how to open YAML files, then you can use some common editors like NotePad++ in windows or vim in linux.
If your question is about running the compose yaml file, then run this command from the directory where compose file is residing:
docker-compose -f {compose file name} up
You can avoid -f if your filename is docker-compose.yml
To manage .yml files you have to install and use Docker Compose.
Installation instructions can be found here: https://docs.docker.com/compose/install/
After the installation, go to your docker-compose.yml directory and then execute docker-compose up to create and start services in your docker-compose.yml file.
If you need more information, take a look to Docker Compose docs: https://docs.docker.com/compose

Resources