Difference between revisions of "Docker Notes"

Line 37: Line 37:
 
<source>
 
<source>
 
http://192.168.1.153:84/webapp.html
 
http://192.168.1.153:84/webapp.html
 +
</source>
 +
 +
accessing to container shell
 +
<source>
 +
> docker run -it ubuntu:latest /bin/bash (enter)
 +
> [ubuntu@shell] >
 +
 +
> exit (to exit)
 +
</source>
 +
 +
you can use all linux commands..
 +
 +
to remove interactive image:
 +
<source>
 +
> docker run -it --rm ubuntu:latest /bin/bash (enter)
 +
> exit (to exit)
 +
</source>
 +
 +
to see the running ubuntu process:
 +
<source>
 +
> docker ps -a | grep ubuntu
 +
</source>
 +
 +
accessing to container shell - 2
 +
<source>
 +
> docker run -it ubuntu:latest /bin/sh (enter)
 +
> [ubuntu@shell] > whoami
 +
 +
> exit (to exit)
 +
</source>
 +
 +
accessing to running container shell
 +
<source>
 +
> docker ps #list process and pick up one
 +
> docker exec -it my_http /bin/bash
 +
> docker ls
 +
 +
> exit (to exit)
 +
</source>
 +
 +
to run php from docker image..
 +
<source>
 +
> docker run -it --rm php:latest /bin/bash #if exist, remove first..
 +
</source>
 +
 +
run a php script mounted in the container using the volume option
 +
<source>
 +
> docker run -it --rm -v "$(pwd)/challenge.php:/home/challenge.php" php:latest /bin/bash
 +
</source>
 +
 +
<source>
 +
> docker run -it --rm [mount] "$(pwd)/[source_file]:[target_address]" php:latest /bin/bash
 
</source>
 
</source>

Revision as of 14:08, 9 October 2018

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