Last Updated: March 08, 2024
·
2.26K
· itseranga

Docker tips

Configuration files

OSX

# on boot2docker
/var/lib/boo2docker/profile

Linux

/etc/default/docker

Example configuration file content

# setting up insecure registry
# 10.2.4.201 is the private registry host
DOCKER_OPTS="$DOCKER_OPTS —insecure-registry=10.2.4.201"

Working with images

List images

docker images

Delete image

docker rmi <image-id>
docker rmi -f <image-id>

# docker rmi 3f5b9885f749

Delete image with specific tag

docker rmi <image-name>:<tag>

# example
docker rmi rabbitmq:0.7

Delete all images

docker rmi $(docker images -q)

Delete dangling images

docker rmi $(docker images -f dangling=true -q)

Copy image from one host to another

## you can compress image as tar file and transfer it
docker save -o <saving name> <image id>
docker save -o db.tar e0d9768dfdbf

## load saved image(compressed file) in to docker
docker load -i <saved file> 
docker load -i db.tar

Working with containers

Start container

docker start <container-id>

Stop container

docker stop <container-id>

Restart container

docker restart <container-id>

List running containers

docker ps

List all containers(running + stopped)

docker ps -a

Containers logs

docker logs <container-id>

Container config details

docker inspect <container-id>

Login/connect to container

docker exec -it <container-id> bash

# example 
docker exec -it adea7b2dbc98 bash

Delete container

docker rm <container-id>
docker rm -f <container-id>

Delete all containers

docker rm $(docker ps -a -q)

Delete all stopped/exited containers

docker rm $(docker ps -a | grep Exited | awk '{print $1}')

Logs

Docker logs

# linux
/var/log/docker.log

# osx(on boot2docker)
/var/log/docker.log
/var/log/boot2docker.log

Container logs

# linux
/var/lib/docker/containers/<container-id>/<container-id>.log

# osx(on boot2docker)
/var/lib/docker/containers/<container-id>/<container-id>.log

Working with private registry

Pull image

docker pull <registry-host>/<image-name>:<tag>

# example
docker pull 10.2.4.201/rabbitmq:0.7

List all images in registry

# via REST api
http ://<registry-host>/v1/search

# example
http ://10.2.4.201/v1/search

Search specific image

# via REST api
http ://<registry-host>/v1/search?<image-name>

# example
http ://10.2.4.201/v1/search?rabbitmq

List available tags of a image

# via REST api
http ://<registry-host>/v1/repositories/<image-name>/tags

# example
http ://10.2.4.201/v1/repositories/rabbitmq/tags

Delete image in private registry

# issue DELETE request with curl from command line
curl -X DELETE "http ://<registry-host>/v1/repositories/<image-name>/"

# example
curl -X DELETE "http ://10.2.4.201/v1/repositories/rabbitmq/"

Delete image with specific tag

# issue DELETE request with curl from command line
curl -X DELETE "http ://<registry-host>/v1/repositories/<image-name>/tags/<tag-name>"

# example
curl -X DELETE "http ://10.2.4.201/v1/repositories/rabbitmq/tags/0.7"