Docker cheat sheet

How to run simple http server with local directory mapped to docker httpd html root
docker run -dit --name my-web-server -p 8080:80 -v /home/user/website/:/usr/local/apache2/htdocs/ httpd:2.4
Point browser to http://localhost:8080 to see the index.html from local /home/user/website/ folder
parameters used:

-v, --volume=[host-src:]container-dest[:options]: Bind mount a volume. The comma-delimited `options` are [rw|ro], [z|Z], [[r]shared|[r]slave|[r]private], and [nocopy]. The 'host-src' is an absolute path or a name value. If neither 'rw' or 'ro' is specified then the volume is mounted in read-write mode.
-p=[] : Publish a host port (8080) to container's port (80)
-P : Publish all container ports to host. use `docker ps` command to see the mapping

Use –add-host to add a line in etc/hosts on docker container
docker run -it --add-host db-static: ubuntu cat /etc/hosts
Use –rm to remove docker container after run
docker run -it --rm ubuntu cat /etc/hosts

Docker windows containers

$ & $Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchDaemon .

$ docker pull 

$ docker run -it cmd.exe 

$ echo "Hello World!" > Hello.txt

$ exit 

$ docker ps -a

$ docker commit <containerid> helloworld  

$ docker run --rm helloworld cmd.exe /s /c type Hello.txt 

Copyright 2005-2016 KnowledgeHills. Privacy Policy. Contact .