Thursday, September 04, 2014

Docker Notes


# see the list of docker images as a tree view. Determine IMAGE_ID
sudo docker images --tree

# get list of currently running containers. Determine CONTAINER_ID
sudo docker ps

# remove a docker image tree
sudo docker rmi IMAGE_ID/TAG

# get list of all containers
sudo docker ps -a

# get last executed container info
sudo docker ps -al

# get all containers without the command being truncated
sudo docker ps -a --no-trunc

# commit changes to a docker container and tag the commit
sudo docker commit CONTAINER_ID feature/nginx

# tag an image without running
sudo docker tag IMAGE_ID TAG_NAME

# run a tag or IMAGE_ID as an interactive bash shell
sudo docker run -t -i -p 80 feature/nginx /bin/bash

# remove the container after running
sudo docker run -rm ….

# name a container
sudo docker run --name …

# run a tag or IMAGE_ID as an interactive ssh process
sudo docker run -t -i -p 22 -p 80 feature/nginx /usr/sbin/sshd -D

# run a tag or IMAGE_ID as a background ssh process
sudo docker run -d -p 22 -p 80 feature/nginx /usr/sbin/sshd -D

# view docker logs
sudo docker logs CONTAINER_ID/NAME
sudo docker logs -f CONTAINER_ID/NAME  # follow

# stop a running container in the background or foreground
sudo docker stop CONTAINER_ID/NAME

# build and tag an image using a Dockerfile
docker build -t tag/name .

# run a docker process and open up ports 22 and 80 on the docker instance. The host ports are generated automatically.
sudo docker run -d -p 22 -p 80 feature/nginx /usr/bin/supervisord -n

# Get port on the host that is NATed to the given port on the image
sudo docker port CONTAINER_ID 22
sudo docker port CONTAINER_ID 80

# run a docker process and map host port 8888 to docker instance port 80 and host port 2222 to docker instance port 22
sudo docker run -d -p 2222:22 -p 8888:80 feature/nginx /usr/bin/supervisord -n

# Same as above but additionally creates a shared folder between the host and guest
sudo docker run -d -p 2222:22 -p 8888:80 -v /home/:/home/:rw feature/nginx /usr/bin/supervisord -n

# clean up extra containers
sudo docker rm `sudo docker ps -a | grep Exit | awk '{ print $1}'`
sudo docker rm $(sudo docker ps -a -q)

# NEW: clean up exited containers 
sudo docker ps -a -q --filter status=exited | xargs docker rm

# NEW: clean up untagged images
docker images -q --filter "dangling=true" | xargs docker rmi

# delete all untagged images
sudo docker rmi $( sudo docker images | grep '' | tr -s ' ' | cut -d ' ' -f 3)

# In Ubuntu, change the docker daemon listen address for Shipyard
DOCKER_OPTS="-H tcp:// -H unix:///var/run/docker.sock"
service restart docker

# images files stored in

# get the host gateway from within the container
netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'

# find metatdata bout the container
sudo docker inspect CONTAINER_ID/NAME

# Setup shipyard-agent
curl -L -o /usr/local/bin/shipyard-agent
chmod +x /usr/local/bin/shipyard-agent

shipyard-agent -url http://myshipyardhost:shipyardport -register # register with shipyard
shipyard-agent -url http://myshipyardhost:shipyardport -key 1234567890qwertyuiop # run the agent

sudo aptitude install nginx vim openssh-server supervisord psmisc

vim /etc/supervisor/conf.d/nginx.conf
command=/usr/sbin/nginx -c /etc/nginx/nginx.conf

vim /etc/supervisor/conf.d/ssh.conf
command=/usr/sbin/sshd -D


CONTAINER_ID=$(docker run -d image-name /bin/bash)
docker export $CONTAINER_ID | docker import – flat-image-name

CONTAINER_ID=$(docker run -d image-name /bin/bash)
(docker export $CONTAINER_ID | gzip -c > image.tgz)
gzip -dc image.tgz | docker import - flat-image-name

--links option

Remove images article

Linking Containers

Dockerfile Reference

FLYNN - Open Source PaaS

ETCD - Configuration Tool

1 comment:

SirVon Thomas said...

god status!