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
Related
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.
Is it possible to check it without getting inside the container?
something like
docker container exec -it <container name> ....
You can check the version using Docker inspect.
docker inspect mysql8 | grep MYSQL_MAJOR
#Or to print version plus major both
docker inspect mysql8 | grep MYSQL_
or without running the container
docker run -it mysql8 bash -c "printenv | grep MYSQL_VERSION"
Or if the container is already running
docker exec mysql bash -c "mysql -V"
You can use exec to run commands against a container:
docker exec -it <container_name> bash -c "mysql -V"
get Container ID:
docker ps
Ex image: enter image description here
Remote to docker & using bash in it:
docker exec -it <container_name> bash
Input command:
mysql -V
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>
My container must be running in host network model (--net=host), so I want the container to stop and report a error if it is not running in a host network.
How can I do it in some script,which is running in the container?
Thanks, the solution works.
Run your container with -v /var/run/docker.sock:/var/run/docker.sock
Download docker from
https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz
tar xf ./docker-latest.tgz
docker cp ./docker/docker :/usr/bin/
docker exec /usr/bin/docker inspect | grep NetworkMode| awk -F '"' '{print $4;}'
Get the network type result: host
I want to run a container and pass it the host IP (which will be visible by the container) as an environment variable to my container, how can I do that ?
Here is what it should like:
docker run -it --rm -e HOST_IP=`script which will give me the host IP visible by the future running container` myimage
docker run -it --rm -e HOST_IP=`/sbin/ip route | awk '/docker/ {print $9 }'` myimage