Last active
August 29, 2015 13:58
-
-
Save arthuralvim/9958319 to your computer and use it in GitHub Desktop.
Playing with Docker.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# creates a container. | |
docker run | |
# stops it. | |
docker stop | |
# will start it again. | |
docker start | |
# restarts a container. | |
docker restart | |
# deletes a container. | |
docker rm | |
# sends a SIGKILL to a container. | |
docker kill | |
# will connect to a running container. | |
docker attach | |
# blocks until container stops. | |
docker wait | |
# shows running containers. | |
docker ps | |
# looks at all the info on a container (including IP address). | |
docker inspect | |
# gets logs from container. | |
docker logs | |
# gets events from container. | |
docker events | |
# shows public facing port of container. | |
docker port | |
# shows running processes in container. | |
docker top | |
# shows changed files in the container's FS. | |
docker diff | |
# -a shows running and stopped containers. | |
docker ps | |
# shows all images. | |
docker images | |
# creates an image from a tarball. | |
docker import | |
# creates image from Dockerfile. | |
docker build | |
# creates image from a container. | |
docker commit | |
# removes an image. | |
docker rmi | |
# to login to a registry. | |
docker login | |
# searches registry for image. | |
docker search | |
# pulls an image from registry to local machine. | |
docker pull | |
# pushes an image to the registry from local machine. | |
docker push | |
# obtain container's ip | |
docker inspect <container id> | grep IPAddress | cut -d '"' -f 4 | |
# obtain environment settings | |
docker run ubuntu env | |
# show image dependencies | |
docker images -viz | dot -Tpng -o docker.png | |
# remove old containers | |
docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs docker rm | |
# stop / remove all Docker containers (https://coderwall.com/p/ewk0mq) | |
docker stop $(docker ps -a -q) | |
docker rm $(docker ps -a -q) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import docker | |
c = docker.Client(base_url='unix://var/run/docker.sock') | |
c.login('username', password='xxxxx', email='my@email.com') | |
# show images | |
c.images() | |
# pull an image from docker repository | |
c.pull('arthuralvim/docker-ubuntu-ssh', tag=None, stream=False) | |
# container commands | |
# + list containers | |
c.containers(all=False) | |
# + create a container | |
container_id = c.create_container('arthuralvim/docker-ubuntu-ssh', command=None, name='teste') | |
# + start the container again | |
c.start(container_id, port_bindings={80: ('127.0.0.1', 8080), 22: ('127.0.0.1', 2222)}) | |
# + inspect container info | |
container_info = c.inspect_container(container_id) | |
container_port = container_info['NetworkSettings']['Ports'] | |
container_ip = container_info['NetworkSettings']['IPAddress'] | |
# do some changes here and then... | |
# + commit changes | |
c.commit(container_id) | |
# + stop a container | |
c.stop(container_id) | |
# or | |
# + kill all processes running in the container | |
c.kill(container_id) | |
# + remove a container | |
c.remove_container(container_id) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
VAGRANTFILE_API_VERSION = "2" | |
$script = <<-SCRIPT | |
apt-get update | |
locale-gen en_US en_US.UTF-8 pt_BR pt_BR.utf8 pt_PT.utf8 | |
dpkg-reconfigure locales | |
apt-get install -y --force-yes curl git | |
curl https://get.docker.io/ubuntu/ | sudo sh | |
usermod -aG docker vagrant | |
SCRIPT | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.box = "ubuntudocker" | |
config.vm.box_url = "http://nitron-vagrant.s3-website-us-east-1.amazonaws.com/vagrant_ubuntu_12.04.3_amd64_virtualbox.box" | |
config.vm.network "forwarded_port", guest: 80, host: 8080 | |
config.vm.network "forwarded_port", guest: 22, host: 2222, id: 'ssh' | |
config.vm.network "private_network", ip: "33.33.33.33" | |
# Setup port forwarding per loaded environment variables | |
for port in 49000..49900 | |
config.vm.network "forwarded_port", guest: port, host: port, auto_correct: true | |
end | |
config.vm.boot_timeout = 60 | |
config.ssh.username = "vagrant" | |
config.ssh.password = "vagrant" | |
config.ssh.host = "127.0.0.1" | |
config.ssh.port = "2222" | |
config.vm.provision "shell", inline: $script | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment