Saturday, August 2, 2014

Docker tricks and tips

https://gist.github.com/wsargent/7049221


http://stackoverflow.com/questions/17157721/getting-a-docker-containers-ip-address-from-the-host?rq=1

How to get the container's IP address ?


You can use docker inspect
Example:
> CID=$(docker run -d -p 4321 base nc -lk 4321); > docker inspect $CID -or-
> docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID}

How to get the full container ID ?


> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d8e703d7e303 solidleon/ssh:latest /usr/sbin/sshd -D cranky_pare
> docker inspect -f '{{.Id}}' cranky_pare
or
> docker inspect -f '{{.Id}}' d8e703d7e303
d8e703d7e3039a6df6d01bd7fb58d1882e592a85059eb16c4b83cf91847f88e5

Where is the full container ID stored ?
It is in the host file system under /var/lib/docker/aufs/mnt/


How to copy file from host to container ?
Get full container ID as mentioned above and then use the 'cp' command from the host
> sudo cp file.txt /var/lib/docker/aufs/mnt/d8e703d7e3039a6df6d01bd7fb58d1882e592a85059eb16c4b83cf91847f88e5/root/file.txt

How to coy file from container to host ?
>docker cp d8e703d7e303:/file/path/within/container /host/path/target


No comments: