Difference between revisions of "Docker Notes"
| Line 89: | Line 89: | ||
<source> | <source> | ||
> docker run -it --rm [mount] "$(pwd)/[source_file]:[target_address]" php:latest /bin/bash | > docker run -it --rm [mount] "$(pwd)/[source_file]:[target_address]" php:latest /bin/bash | ||
| + | </source> | ||
| + | |||
| + | installing software to a Docker Image... | ||
| + | <source> | ||
| + | > vi Dockerfile | ||
| + | FROM ubuntu:latest | ||
| + | |||
| + | # apt-get update : checks program updates | ||
| + | # apt-get install -y : ask yes/no for installation for new update | ||
| + | # --no-install-recommends vim : don't install lib update for vim | ||
| + | RUN apt-get update && apt-get install -y --no-install-recommends vim && apt-get clean | ||
| + | |||
| + | (save & exit) | ||
| + | > docker built . -t ubuntu-vim # it updates ubuntu and install vim.. | ||
| + | > docker images | ||
| + | > docker run -it --rm ubuntu-vim /bin/bash # run | ||
| + | </source> | ||
| + | |||
| + | access container console logs .. | ||
| + | |||
| + | <source> | ||
| + | > docker logs -h # shows log options | ||
| + | > docker logs -f --tail 10 readmine | ||
| + | </source> | ||
| + | |||
| + | to see apache logs.. | ||
| + | |||
| + | <source> | ||
| + | > docker run -d -p httpd | ||
| + | > docker ps | ||
| + | > docker logs -f xxxxxxx_images | ||
| + | </source> | ||
| + | |||
| + | docker container healthcheck | ||
| + | <source> | ||
| + | > CURL -I "http://localhost:8080" # it show header info about address | ||
| + | > CURL -I -f "http://localhost:8080" | ||
| + | > CURL -I "http://localhost:8080" || exit 1 | ||
| + | |||
| + | #how to check in docker image | ||
| + | > vi Dockerfile | ||
| + | FROM httpd:latest | ||
| + | |||
| + | RUN apt-get update && apt-get install -y --no-install-recommends curl && apt-get clean | ||
| + | |||
| + | EXPOSE 80 | ||
| + | |||
| + | # --interval=15s : every 15s check | ||
| + | # --retries=5 : if fail, 5 times retry | ||
| + | # --start-period=30s : when server run, 30s later start to check | ||
| + | # CMD : run that commands after CMD | ||
| + | HEALTHCHECK --interval=15s --retries=5 --timeout=30s --start-period=30s CMD curl -I -f "http://localhost:80" || exit 1 | ||
| + | |||
| + | (save & exit) | ||
| + | |||
</source> | </source> | ||
Revision as of 11:00, 10 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 serverto 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]:versionto test go to container ip address, and test:
http://192.168.1.153:84/webapp.htmlaccessing 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 ubuntuaccessing 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/bashinstalling software to a Docker Image...
> vi Dockerfile
FROM ubuntu:latest
# apt-get update : checks program updates
# apt-get install -y : ask yes/no for installation for new update
# --no-install-recommends vim : don't install lib update for vim
RUN apt-get update && apt-get install -y --no-install-recommends vim && apt-get clean
(save & exit)
> docker built . -t ubuntu-vim # it updates ubuntu and install vim..
> docker images
> docker run -it --rm ubuntu-vim /bin/bash # runaccess container console logs ..
> docker logs -h # shows log options
> docker logs -f --tail 10 readmineto see apache logs..
> docker run -d -p httpd
> docker ps
> docker logs -f xxxxxxx_imagesdocker container healthcheck
> CURL -I "http://localhost:8080" # it show header info about address
> CURL -I -f "http://localhost:8080"
> CURL -I "http://localhost:8080" || exit 1
#how to check in docker image
> vi Dockerfile
FROM httpd:latest
RUN apt-get update && apt-get install -y --no-install-recommends curl && apt-get clean
EXPOSE 80
# --interval=15s : every 15s check
# --retries=5 : if fail, 5 times retry
# --start-period=30s : when server run, 30s later start to check
# CMD : run that commands after CMD
HEALTHCHECK --interval=15s --retries=5 --timeout=30s --start-period=30s CMD curl -I -f "http://localhost:80" || exit 1
(save & exit)