Difference between revisions of "Docker Notes"

Line 144: Line 144:
 
(save & exit)
 
(save & exit)
  
 +
> docker built . -t httpd-oasis
 +
 +
#docker run -d -p --name [new-image-alias] [docker-image]
 +
> docker run -d -p --name http-my-oasis http-oasis
 +
 +
> docker ps #we will see healtcheck..
 +
 +
> docker logs -f httpd-my-oasis #to see the logs..
 +
</source>
 +
 +
 +
linking docker containers...
 +
<source>
 +
> docker run -d --name resuse-httpd httpd
 +
 +
# docker run -it --link "[container-name or id]:[alias]" php-apache-wget /bin/bash
 +
> docker run -it --link "reuse-httpd:web" php-apache-wget /bin/bash
 +
 +
> wget "http://web:80"
 +
> cat index.html
 
</source>
 
</source>

Revision as of 12:24, 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 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

installing 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  # run

access container console logs ..

> docker logs -h # shows log options
> docker logs -f --tail 10 readmine

to see apache logs..

> docker run -d -p httpd
> docker ps
> docker logs -f xxxxxxx_images

docker 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)

> docker built . -t httpd-oasis

#docker run -d -p --name [new-image-alias] [docker-image] 
> docker run -d -p --name http-my-oasis http-oasis 

> docker ps #we will see healtcheck..

> docker logs -f httpd-my-oasis #to see the logs..


linking docker containers...

> docker run -d --name resuse-httpd httpd

# docker run -it --link "[container-name or id]:[alias]" php-apache-wget /bin/bash
> docker run -it --link "reuse-httpd:web" php-apache-wget /bin/bash

> wget "http://web:80"
> cat index.html