Difference between revisions of "Docker/Current/Troubleshooting/Troubleshooting"
From Genesys Documentation
(Published) |
(Published) |
||
Line 7: | Line 7: | ||
==Troubleshooting Docker Containers== | ==Troubleshooting Docker Containers== | ||
<ol> | <ol> | ||
+ | <li>Get the IP address. To do this, run the following command. | ||
+ | <source lang="xml"> docker inspect $(dl) | grep -wm1 IPAddress | cut -d '"' -f 4</source>Or, install jQuery and run the following command. | ||
+ | <source lang="xml">docker inspect $(dl) | jq -r '.[0].NetworkSettings.IPAddress'</source>Or install [https://docs.docker.com/engine/reference/commandline/inspect go template] and run the following command. <source lang="xml">docker inspect -f '{{ .NetworkSettings.IPAddress }}' <container_name></source> To pass a build argument when building an image from Dockerfile: | ||
+ | <source lang="xml">DOCKER_HOST_IP=`ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1` | ||
+ | echo DOCKER_HOST_IP = $DOCKER_HOST_IP | ||
+ | docker build \ | ||
+ | --build-arg ARTIFACTORY_ADDRESS=$DOCKER_HOST_IP | ||
+ | -t sometag \ | ||
+ | some-directory/ | ||
+ | </source></li> | ||
+ | <li>Get port mapping | ||
+ | <source lang="xml">docker inspect -f '{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' <containername></source></li> | ||
+ | <li>Find containers by regular expression | ||
+ | <source lang="xml">for i in $(docker ps -a | grep "REGEXP_PATTERN" | cut -f1 -d" "); do echo $i; done</source></li> | ||
<li>Get environment settings. | <li>Get environment settings. | ||
<source lang="xml">docker run --rm ubuntu env</source></li> | <source lang="xml">docker run --rm ubuntu env</source></li> | ||
Line 29: | Line 43: | ||
<li> Show image dependencies. | <li> Show image dependencies. | ||
<source lang="xml">docker images -viz | dot -Tpng -o docker.png</source></li> | <source lang="xml">docker images -viz | dot -Tpng -o docker.png</source></li> | ||
− | <li> | + | <li>Slimming down Docker containers. |
'''Cleaning APT in a RUN layer''': | '''Cleaning APT in a RUN layer''': | ||
This must be done in the same layer as that of the other APT commands. If not, the previous layers will still contain the original information and your images will still be large. | This must be done in the same layer as that of the other APT commands. If not, the previous layers will still contain the original information and your images will still be large. |
Revision as of 18:35, November 2, 2019
This topic is part of the manual Running Containers and Troubleshooting for version Current of Genesys Docker Documentation.
Information about how to troubleshoot docker containers.
Troubleshooting Docker Containers
- Get the IP address. To do this, run the following command.
Or, install jQuery and run the following command.
docker inspect $(dl) | grep -wm1 IPAddress | cut -d '"' -f 4
Or install go template and run the following command.docker inspect $(dl) | jq -r '.[0].NetworkSettings.IPAddress'
To pass a build argument when building an image from Dockerfile:docker inspect -f '{{ .NetworkSettings.IPAddress }}' <container_name>
DOCKER_HOST_IP=`ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1` echo DOCKER_HOST_IP = $DOCKER_HOST_IP docker build \ --build-arg ARTIFACTORY_ADDRESS=$DOCKER_HOST_IP -t sometag \ some-directory/
- Get port mapping
docker inspect -f '{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' <containername>
- Find containers by regular expression
for i in $(docker ps -a | grep "REGEXP_PATTERN" | cut -f1 -d" "); do echo $i; done
- Get environment settings.
docker run --rm ubuntu env
- Kill running containers.
docker kill $(docker ps -q)
- Delete all containers (force!! running or stopped containers).
docker rm -f $(docker ps -qa)
- Delete old containers.
docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs docker rm
- Delete stopped containers.
docker rm -v $(docker ps -a -q -f status=exited)
- Delete containers after stopping.
docker stop $(docker ps -aq) && docker rm -v $(docker ps -aq)
- Delete dangling images.
docker rmi $(docker images -q -f dangling=true)
- Delete all images.
docker rmi $(docker images -q)
- Delete dangling volumes.
As of Docker 1.9.0:
In 1.9.0, the filter dangling=false does not work. It is ignored and lists all volumes.
docker volume rm $(docker volume ls -q -f dangling=true)
- Show image dependencies.
docker images -viz | dot -Tpng -o docker.png
- Slimming down Docker containers.
Cleaning APT in a RUN layer:
This must be done in the same layer as that of the other APT commands. If not, the previous layers will still contain the original information and your images will still be large.
RUN {apt commands} \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Flatten an image:
ID=$(docker run -d image-name /bin/bash)
docker export $ID | docker import – flat-image-name
For backup:
ID=$(docker run -d image-name /bin/bash)
(docker export $ID | gzip -c > image.tgz)
gzip -dc image.tgz | docker import - flat-image-name
Information on Running Docker Containers
docker ps
displays running containers.docker logs
gets logs from the container. (You can use a custom log driver, but logs are available only for json-file and journald in 1.10).docker inspect
inspects all the information of a container (including the IP address).docker events
gets events from the container.docker port
displays the public facing port of the container.docker top
displays the running processes in container.docker stats
displays the containers' resource usage statistics.docker diff
displays the changed files in the container's FS.docker ps -a
displays running and stopped containers.docker stats --all
displays a running list of containers.docker update
updates a container's resource limits.
To check the CPU, memory, and network I/O usage of a single container:
docker stats <container>
For all containers listed by ID:
docker stats $(docker ps -q)
For all containers listed by name:
docker stats $(docker ps --format '{{.Names}}')
For all containers listed by image:
docker ps -a -f ancestor=ubuntu
To remove all untagged images:
docker rmi $(docker images | grep “^” | awk '{split($0,a," "); print a[3]}')
To remove container by a regular expression:
docker ps -a | grep wildfly | awk '{print $1}' | xargs docker rm -f
To remove all exited containers:
docker rm -f $(docker ps -a | grep Exit | awk '{ print $1 }')
Comments or questions about this documentation? Contact us for support!