Dicas do Docker

Arquivos de configuração

OSX

# on boot2docker
/var/lib/boo2docker/profile

Linux

/etc/default/docker

Exemplo de conteúdo do arquivo de configuração

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

Trabalhando com imagens

Listar imagens

docker images

Apagar imagem

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

# docker rmi 3f5b9885f749

Excluir imagem com tag específica

docker rmi <image-name>:<tag>

# example
docker rmi rabbitmq
:0.7

Apagar todas as imagens

docker rmi $(docker images -q)

Excluir imagens pendentes

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

Copie a imagem de um host para outro

## 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

Trabalhando com contêineres

Iniciar contêiner

docker start <container-id>

Parar o recipiente

docker stop <container-id>

Reiniciar contêiner

docker restart <container-id>

Listar contêineres em execução

docker ps

Listar todos os contêineres (em execução + interrompido)

docker ps -a

Registros de contêineres

docker logs <container-id>

Detalhes de configuração do contêiner

docker inspect <container-id>

Faça login / conecte-se ao contêiner

docker exec -it <container-id> bash

# example
docker
exec -it adea7b2dbc98 bash

Excluir contêiner

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

Excluir todos os contêineres

docker rm $(docker ps -a -q)

Excluir todos os contêineres parados / encerrados

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

Histórico

Registros do Docker

# linux
/var/log/docker.log

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

Logs de contêineres

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

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

Trabalhando com registro privado

Puxar imagem

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

# example
docker pull
10.2.4.201/rabbitmq:0.7

Liste todas as imagens no registro

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

# example
http
://10.2.4.201/v1/search

Pesquisar imagem específica

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

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

Lista as tags disponíveis de uma imagem

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

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

Excluir imagem no registro privado

# 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/"

Excluir imagem com tag específica

# 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"