Docker Notes

Building && Running APP

  > mkdir nginx-webapp
  > cd nginx-webapp
  > vi webapp.html
  > <html><body>...first app..</body></html>
  > vi nginx.conf #server conf file..
server{
   root /www;
}
  > vi Dockerfile  # dockerfile is blueprint of our image 
FROM nginx:latest #or version

ADD webapp.html /www/
ADD nginx.conf /etc/nginx/conf.d/default.conf

#EXPOSE 80
#EXPOSE 443

#CMD nginx -g "deamon off;" #to start nginx server

to start & test

>docker build . -t webapp-oasis:latest
>docker run webapp-oasis
>docker ps #to see docker running images..

to run as a background process

>docker run -d -p 84:80 webapp-oasis:latest #docker [deamon(background process)] [port] [hostport]:[containerport] [docker-image]:version

to test go to container ip address, and test:

http://192.168.1.153:84/webapp.html

accessing to container shell

> docker run -it ubuntu:latest /bin/bash (enter) 
> [ubuntu@shell] > 

> exit (to exit)

you can use all linux commands..

to remove interactive image:

> docker run -it --rm ubuntu:latest /bin/bash (enter) 
> exit (to exit)

to see the running ubuntu process:

> docker ps -a | grep ubuntu

accessing to container shell - 2

> docker run -it ubuntu:latest /bin/sh (enter) 
> [ubuntu@shell] > whoami

> exit (to exit)

accessing to running container shell

> docker ps #list process and pick up one 
> docker exec -it my_http /bin/bash
> docker ls

> exit (to exit)

to run php from docker image..

> docker run -it --rm php:latest /bin/bash #if exist, remove first..

run a php script mounted in the container using the volume option

> docker run -it --rm -v "$(pwd)/challenge.php:/home/challenge.php" php:latest /bin/bash
> docker run -it --rm [mount] "$(pwd)/[source_file]:[target_address]" php:latest /bin/bash