2 minutes
Docker
Run container and attach a bash : docker run -i -t ubuntu /bin/bash
Run detach : docker run -d ubuntu /bin/sh -c "<command>"
Run options
-d : detach
-P : bind app port to random port on host
-p : : specify port to bind
–name : specify a name (unique) for container
–net=my-bridge-network : specify the network
-v /myvolume : specify a volume to mount in container
-v /path/hostvolume:/path/containervolume: : mount an host volume into container with option (ro/rw etc ⇒ rw default)
Some commands
General
docker ps (-a) : Lists (running) containers.
docker logs (-f) : Shows us the standard output of a container (-f acts like tail -f).
docker stop/start/restart : Stops/starts/restarts containers.
docker attach : Attach a running container
docker port : return port on host
docker inspect : return JSON with the container info
docker rm : delete container
docker exec : exec command in a running container
Network
docker network ls : list network option
docker network inspect bridge : list container network info
docker network disconnect bridge : disconnect container
docker network create -d bridge my-bridge-network : create your bridge
docker network connect my-bridge-network : connect container to network
Volume
docker volume create -d flocker –name my-named-volume -o size=20GB : create a volume
docker run –rm -it -v yourfile:path_tofile image /bin/bash : mount file to the container
docker create -v /dbdata –name dbstore image /bin/true : create a volume container
Mount the previous volume :
docker run -d –volumes-from dbstore –name named1 image
docker run -d –volumes-from dbstore –name named2 image
Modifying docker images
Commiting
DON’T REALLY DO THAT
docker run -t -i <base image> /bin/bash
Do some stuff in container : apt-get install nginx
Exit container and run :
docker commit -m "message" -a "your name" <container_id> ouruser/test:v2(target)
Dockerfile
mkdir /image
touch /image/Dockerfile
echo "# This is a comment
FROM ubuntu:14.04
MAINTAINER Thomas <thomas@example.com>
RUN apt-get update && apt-get install -y nginx" > /image/Dockerfile
Built it : docker build -t repo/image:tag .
Use it : docker run -t -i repo/image:tag /bin/bash
Tag it : docker tag <id> repo/image:<tag>