O objetivo primário do Docker é rodar containers.
Serve para: testing, CI/CD, configurar PaaS
Verificar a instalação do Docker (info do Client e do Server):
$ docker version
Um container é iniciado por uma Imagem. As Imagens ficam hospedadads no Docker Registry. Pesquisa Imagens no registro.
$ docker search <term>
docker search --limit 5 alpine
Para baixar a imagem mais recente:
$ docker pull <name>
Para listar todas as imagens baixadas:
$ docker image ls
$ docker images
$ docker container run -i -t --name mycontainer <image_name> /bin/bash
-i : modo interativo -t : vincula o tty do container à entrada padrão
$ docker container run -i -t alpine /bin/ash
Para sair:
exit ou Ctrl+D
$ docker container ls
$ docker ps
$ docker container logs <CONTAINER>
$ docker container stop <CONTAINER>
Parar todos os containers:
$ docker stop $(docker ps -q)
$ docker container rm <CONTAINER>
Deve parar o container antes de remover.
$ docker container rm <CONTAINER> -f
docker container rm $(docker container ls –aq)
$ docker container create --name c1 alpine /bin/ash
$ docker container run --name c2 alpine /bin/ash
$ docker container ls -a
$ docker container prune
$ docker container ls -a
Docker volumes are a special directory in the Docker host, and are created and managed by Docker itself.
We can mount these volumes to our container and have the application store its data to the volume.
Docker also supports the volume plugin to address advanced storage needs, which is outside the scope of this book.
$ docker volume create <NAME>
$ docker volume create ls
$ docker container run -it --rm -v datavol:/data alpine/ #
creates a directory for the volume under the /var/lib/docker/volumes/ directory of the Docker host.
$ docker volume inspect
$ docker container run -it --rm -v $HOME/docker_share:/data alpine