How can I access the stdout & stderr of a running docker container?
When I inspect the container with docker inspect <id> | grep log I receive the following:
"LogPath": "/var/lib/docker/containers/<long id>-json.log"
But I can't find the file neither on my current folder, nor when trying to run docker exec <id> cat /var/lib/docker/containers/<long id>-json.log
edit running docker log <id> doesn’t give anything either
I am launching the container with the following command:
docker run -d -it --log-driver json-file --rm --log-opt max-size=10m --log-opt max-file=3 <my_app>
What am I missing/forgetting?
Try :
docker logs <container ID>
Related
Any commands hang terminal inside docker container.
I login in container with docker exec -t php-zts /bin/bash
And then print any elementary command (date, ls, cd /, etc.)
Command hang
When I press ctrl+c I going back to host machine.
But, if I run any command without container - it's work normally
docker exec -t php-zts date
Wed Jan 26 00:04:38 UTC 2022
tty is enabled in docker-compose.yml
docker system prune and all cleanups can not help me.
I can't identify the problem and smashed my brain. Please help :(
The solution is to use the flag -i/--interactive with docker run. Here is a relevant section of the documentation:
--interactive , -i Keep STDIN open even if not attached
You can try to run your container using -i for interactive and -t for tty which will allow you to navigate and execute commands inside the container
docker run -it --rm alpine
In the other hand you can run the container with docker run then execute commands inside that container like so:
tail -f /dev/null will keep your container running.
-d will run the command in the background.
docker run --rm -d --name container1 alpine tail -f /dev/null
or
docker run --rm -itd --name container1 alpine sh # You can use -id or -td or -itd
This will allow you to run commands from inside the container.
you can choose sh, bash, or any other shell you prefer.
docker exec -it container1 alpine sh
I am trying to follow:
https://dev.to/_nicolas_louis_/how-to-run-docker-on-windows-without-docker-desktop-hik
in order to use docker on wsl2 from Windows.
I can start a docker container with this call:
docker -H 127.0.0.1 run --rm hello-world
however, when I obtain the IP address with:
echo `ifconfig eth0 | grep -E "([0-9]{1,3}.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d:`
and try to start the container with:
docker -H 172.26.110.78 run --rm hello-world
I get the following error:
docker: Cannot connect to the Docker daemon at tcp://172.26.110.78:2375. Is the docker daemon running?.
Ping works and docker daemon runs, obviously.
What can I do to fix the problem?
try restarting your docker container as it might be not running in a proper state.
Use:
docker restart [OPTIONS] CONTAINER [CONTAINER...]
For Example:
docker restart hello_world
Why can't I attach to docker container of mariadb?
$ docker run --name mariadbtest -e MYSQL_ROOT_PASSWORD=mypass -d mariadb/server:10.1
<SKIPPED>
78cadba14946919a3d62e1c616e39e76508107d24c6c1b93da534d3a3eb09e2d
$ docker attach 78cadba14946
<HANG>
How to see parameters of this container?
Also I can't ssh to the container
$ docker inspect -f "{{ .NetworkSettings.IPAddress }}" mariadbtest
172.17.0.2
$ ssh 172.17.0.2
<HANG>
docker attach <container> attaches your terminal stream to the container stdout/stderr. If the container sends nothing to these streams - you will see nothing after attaching to it. Try executing some statement in the database and see if anything appears.
As for ssh, normally containers do not have ssh in it. Use docker exec -it <container> sh instead.
I have a container started as the following:
docker run --interactive --tty --gpus all --name my_container
--workdir "/home/ubuntu" --user ubuntu
--volume /hdd/all_cv/paiv/metis:/home/ubuntu/my --publish 8888:8888 my
how do I run interactively with my_container once I reboot my machine?
Based on the docker documentation, you can attach back to the detached container using docker attach command:
Use docker attach to attach your terminal’s standard input, output, and error (or any combination of the three) to a running container using the container’s ID or name. This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.
So you should try this to have an interactive session with your already running container:
docker attach my_container
If your container is stopped, you just need to start it again
docker ps -aq -f name=my_container | xargs docker start $1
Is there any method to get the running docker container's startup arguments? E.g.:
docker run -d -it --privileged --net=host --name oracle-net-host1 -v /oracle_data/oracle1:/data mike/oracle12c:latest
I can get "-d -it --privileged --net=host --name oracle-net-host1 -v /oracle_data/oracle1:/data mike/oracle12c:latest".
I have tried "docker ps -a --no-trunc", but it can't get arguments.
There isn't one but you can query the individual parts using docker inspect.
docker inspect -f '{{.NetworkSettings.Networks}}' oracle-net-host1
Gives something like this:
map[host:0xc876448c99]
Similarly
docker inspect -f '{{.Mounts}}' oracle-net-host1
would give
[{ /oracle_data/oracle1 /data local rprivate }]
I'm sure there are ways to make the output more friendly