I am trying to run docker-compose ps and docker-compose logs and neither are showing any output. I was able to run docker-compose up and verified the correct containers are started with docker ps. However docker-compose logs and ps dont show anything
> sudo docker-compose -f /opt/docker-compose/server1-compose.yml ps
Name Command State Ports
------------------------------
> sudo docker-compose -f /opt/docker-compose/server1-compose.yml logs
Attaching to
Both commands are returning intended output. What is wrong here?
docker-compose version: 1.4.2
Docker version 1.7.1, build 786b29d
thanks so #dnephin to posting a response. For completeness here it is:
dnephin-
" I suspect what's happening here is that the project name is
different. The default project name is the basename of a directory, so
if you run docker-compose from a different directory you might get a
different project name.
You can set it with either -p or COMPOSE_PROJECT_NAME environment
variable. If you look at the first part of the container names (before
the first underscore) that's the project name.
There are open issues to configure the project name from a file. I
think we'll be looking to implement that soon."
Adding the -p switch to my compose command fixed the issue.
ie: sudo docker-compose -f /opt/docker-compose/server1-compose.yml logs -p projectname
Related
Via my local I would like to run docker-compose on my remote machine. I have found two ways that should accomplish this but am running into errors.
Fist I am running the following versions:
me:api$ docker-compose -v
docker-compose version 1.29.2, build unknown
me:api$ docker -v
Docker version 20.10.7, build 20.10.7-0ubuntu5~20.04.2
First way and the way I would prefer for this to work is to the the --context flag. Based on this blog post should be possible.
I created the context like so:
docker context create prod --docker "host=ssh://user#host.com"
I can then run the following and get an output of running containers
docker --context prod ps
However running with docker-compose the command fails
docker-compose --context prod -f docker-compose.yml -f docker-compose.prod.yml up -d
ERROR: Context 'prod' not found
The other option was to use the -H flag based on this SO answer to set the host that I want to execute the commands on. Yes I can SSH into my machine with the user I am using.
docker-compose -H ssh://user#host -f docker-compose.yml -f docker-compose.prod.yml up -d
/bin/sh: 1: ssh: Permission denied
Well it does not look great. I have not been able to get any of the methods to work with docker-compose however there is a new (at the time of writing this) docker compose replacement from docker. The instructions are here. I was hoping that the --context flag would work but it is not found with the new version which leads me to believe that it did not work before. The -H flag lead to the same Permission Denied error as before.
The only way I was able to get this to work was by setting the DOCKER_HOST environment variable.
I've got an issue on ubuntu 18.04 where occasionally running docker-compose up results in the containers starting, the networking between them behaving as expected yet according to docker-compose they aren't there.
docker ps shows the containers exist.
UPDATE: after some comments:
docker-compose ps shows nothing. Also, the problem is intermittent meaning any example is hard to come by unfortunately.
Do you see them in docker ps -a ? You should add docker-compose -d up for detached mode.
Try running
docker-compose ps
from where your .yml file is located. It will show you the list of all docker containers generated from that .yml file
I'm trying to stop a container generated by a docker-compose up but I can't find where this docker-compose was started. If I try to kill the docker container it is automatically recreated (as expected since it is docker-compose).
When running the command docker-compose ps in the folder containing the docker-compose.yml file I get an empty result, so it should be somewhere else...
How can I find where the docker compose is running and finally stop it?
Use docker ps -a | grep <certain_container>
Use locate docker-compose.yml and find the one that you want
Use docker-compose down
Option #1:
Install docker-compose which would be available on your path using the official instructions - https://docs.docker.com/compose/install/.
You can then go to the folder containing the docker-compose.yml and run docker-compose down.
Option #2:
Search for the file using something like:
find / -name "docker-compose"
You can then use the absolute path when running the command.
Option #3:
Update your containers restart policy:
docker update --restart=no container_name
Is there any way to find a source of the docker container script? I have a setup where I can not find any docker-compose.yml file nor the bash script etc that would have run all the Docker containers currently running. I have a virtual machine that starts docker containers on the startup, but have no idea which file is actually run.
i think no option to know which docker-compose file is use.
but you can check manual every you project folder.
the docker-compose mechanism is by matching the docker-compose.yml file. so if you run command sudo docker-compose ps in every your project folder. docker-compose will match between the docker-compose file used by container and docker-compose file in your project, if the same than the results will be displayed, if not the results is not displayed
If the containers are running automatically on reboot and you have no cron/bash profile/rc.local or any other startup screen then that may mean that they are containers with --restart option set. You can change that by running below command
docker ps -q | xargs docker update --restart no
docker ps -q | xargs docker stop
Then restart the machine. The containers should not start. If they do then you have some script somewhere which is starting them
I am not clearly understand how docker-compose realizes when to recreate container or where not.
My case is:
docker-compose -f conf.yml up // Ok
docker-compose -f conf.yml up // xxx is up-to-date
Then I do:
docker-compose -f /copy/conf.yml up // Recreating container
But copy/conf.yml is same as conf.yml
Why docker-compose recreates container, while it's config is unchanged? Its only loaded from other path. How docker-compose handles this stuff?
It must says "up-to-date", if config is same, despite of config's path (I know about --no-recreate flag, but I want to know how things works)
If one folder is /app/conf.yml and the other folder is /app_copy/conf.yml, then you'll find that docker creates two different "projects", one for "app" and the other for "appcopy" (it removes non-alphanumeric characters and makes it all lower case). The project is the first part of each container name by default, it's named $project_$service_$instance.
If you specify the container name inside your docker-compose.yml, then docker-compose will recreate it if you have things like volume mounts to the current folder which would be different. Otherwise, if the compose files are truly identical, the source image hasn't changed, and there are no externalities that would be different, then I'm not able to reproduce this one.
Here's an example without a fixed container_name:
$ docker-compose -f docker-compose.test.yml up -d
Creating test_testapp_1
$ docker-compose -f test/docker-compose.test.yml up -d
test_testapp_1 is up-to-date
Below is what happens if you try to specify a container name in the compose file:
$ pwd
..../test
$ docker-compose -f docker-compose.name.yml up -d
Starting unique_name
$ docker-compose -f subdir/docker-compose.name.yml up -d
Creating network "subdir_default" with the default driver
Creating unique_name
ERROR: for test Cannot create container for service test: Conflict. The container name "/unique_name" is already in use by container 80b44bc94912b755cf2430b132fa6112f960e2752f69a357c27375bbc905ff76. You have to remove (or rename) that container to be able to reuse that name.
$ mv subdir test
$ docker-compose -f test/docker-compose.name.yml up -d
unique_name is up-to-date