Docker :
=> Docker client
=> Docker daemon
Docker client: Its a dumb process it knows only how to speak with Daemon.
Daemon will do actual work.
=> When you run any command like "docker run hello-world".First docker client will forward this info to docker daemon to check, if the image is not available then it will pull from repository(Docker hub).
Docker group : Which ever the users are part of this group those users only will communicate with docker.
===================
How to assign name to the container:
$ docker container run --name container1 alpine
=> If you want to go inside a container just use "-ti" and "/bin/sh"
$ docker container run --name container1 -ti alpine /bin/sh
ubuntu@ip-172-31-2-125:~$ docker container run --name cont9 -ti alpine /bin/sh
/ #
=========================
To comeout from conatiner withput stop:
ctrl+pq => with this comaand you can come outside without stop.
=> if you use "exit" it will stop container.
===================
USER Instruction => it creates the user & it will switch as user
----------------------------------------------------------------------------------------------------------------------
WORKDIR INSTRCUTION => change your starting directory to some thing else
Run container attached mode:
-------------------------------------
ubuntu@ip-172-31-2-125:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins latest cd14cecfdb3a 6 months ago 696MB
ubuntu@ip-172-31-2-125:~$ docker container run -p 8080:8080 jenkins <= default its a attach mode
Run container in background:
-----------------------------------
ubuntu@ip-172-31-2-125:~$ docker container run -d -p 8080:8080 jenkins <=Detach mode
7193a2094a0a149b85d07eb598c6d36d074d6b65245e4c263872df778a43159b
ubuntu@ip-172-31-2-125:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7193a2094a0a jenkins "/bin/tini -- /usr/l…" 18 seconds ago Up 17 seconds 0.0.0.0:8080->8080/tcp, 50000/tcp gracious_kalam
ubuntu@ip-172-31-2-125:~$
=========================
How to go container:
-------------------------
ubuntu@ip-172-31-2-125:~/images/yesu$ docker container run -ti yesuubunut /bin/bash
root@5814441c5df7:/# git --version
git version 2.7.4
How to see the log explicitly when you run container in detach mode:
----------------------------------------------------------------------------------
=> docker log "conatiner name"
ubuntu@ip-172-31-2-125:~$ docker logs gracious_kalam
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
How to attch container:
---------------------------
ubuntu@ip-172-31-2-125:~$ docker container run -d -p 8080:8080 jenkins
1894af306afdbce7525d9f163b638a1d34533effb8c340a6c6f36c7ac40e6022
ubuntu@ip-172-31-2-125:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1894af306afd jenkins "/bin/tini -- /usr/l…" 18 seconds ago Up 17 seconds 0.0.0.0:8080->8080/tcp, 50000/tcp gracious_kalam
ubuntu@ip-172-31-2-125:~$ docker container attach 7193a2094a0a
Feb 08, 2019 7:07:10 AM hudson.model.UpdateSite updateData
INFO: Obtained the latest update center data file for UpdateSource default
Feb 08, 2019 7:07:10 AM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
--> setting agent port for jnlp
--> setting agent port for jnlp... done
Feb 08, 2019 7:07:11 AM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tools.JDKInstaller
Feb 08, 2019 7:07:11 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Finished Download metadata. 9,717 ms
Feb 08, 2019 7:07:11 AM hudson.model.UpdateSite updateData
INFO: Obtained the latest update center data file for UpdateSource default
Feb 08, 2019 7:07:11 AM hudson.WebAppMain$3 run
INFO: Jenkins is fully up and running
=======================================================================
Best Practices for Writing Docker files:
Dockerfile is a step by step process by manually doing
=> Docker daemon
Docker client: Its a dumb process it knows only how to speak with Daemon.
Daemon will do actual work.
=> When you run any command like "docker run hello-world".First docker client will forward this info to docker daemon to check, if the image is not available then it will pull from repository(Docker hub).
Docker group : Which ever the users are part of this group those users only will communicate with docker.
===================
How to assign name to the container:
$ docker container run --name container1 alpine
=> If you want to go inside a container just use "-ti" and "/bin/sh"
$ docker container run --name container1 -ti alpine /bin/sh
ubuntu@ip-172-31-2-125:~$ docker container run --name cont9 -ti alpine /bin/sh
/ #
=========================
To comeout from conatiner withput stop:
ctrl+pq => with this comaand you can come outside without stop.
=> if you use "exit" it will stop container.
===================
USER Instruction => it creates the user & it will switch as user
USER tomcat=> If you mention "USER USERNAME" in dockerfile. it will create user and it will switch to that user.
----------------------------------------------------------------------------------------------------------------------
WORKDIR INSTRCUTION => change your starting directory to some thing else
FROM ubuntu:trusty
RUN apt-get update && apt-get install git -y
USER git
WORKDIR /home/git
Run container attached mode:
-------------------------------------
ubuntu@ip-172-31-2-125:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins latest cd14cecfdb3a 6 months ago 696MB
ubuntu@ip-172-31-2-125:~$ docker container run -p 8080:8080 jenkins <= default its a attach mode
Run container in background:
-----------------------------------
ubuntu@ip-172-31-2-125:~$ docker container run -d -p 8080:8080 jenkins <=Detach mode
7193a2094a0a149b85d07eb598c6d36d074d6b65245e4c263872df778a43159b
ubuntu@ip-172-31-2-125:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7193a2094a0a jenkins "/bin/tini -- /usr/l…" 18 seconds ago Up 17 seconds 0.0.0.0:8080->8080/tcp, 50000/tcp gracious_kalam
ubuntu@ip-172-31-2-125:~$
=========================
How to go container:
-------------------------
ubuntu@ip-172-31-2-125:~/images/yesu$ docker container run -ti yesuubunut /bin/bash
root@5814441c5df7:/# git --version
git version 2.7.4
How to see the log explicitly when you run container in detach mode:
----------------------------------------------------------------------------------
=> docker log "conatiner name"
ubuntu@ip-172-31-2-125:~$ docker logs gracious_kalam
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
How to attch container:
---------------------------
ubuntu@ip-172-31-2-125:~$ docker container run -d -p 8080:8080 jenkins
1894af306afdbce7525d9f163b638a1d34533effb8c340a6c6f36c7ac40e6022
ubuntu@ip-172-31-2-125:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1894af306afd jenkins "/bin/tini -- /usr/l…" 18 seconds ago Up 17 seconds 0.0.0.0:8080->8080/tcp, 50000/tcp gracious_kalam
ubuntu@ip-172-31-2-125:~$ docker container attach 7193a2094a0a
Feb 08, 2019 7:07:10 AM hudson.model.UpdateSite updateData
INFO: Obtained the latest update center data file for UpdateSource default
Feb 08, 2019 7:07:10 AM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
--> setting agent port for jnlp
--> setting agent port for jnlp... done
Feb 08, 2019 7:07:11 AM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tools.JDKInstaller
Feb 08, 2019 7:07:11 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Finished Download metadata. 9,717 ms
Feb 08, 2019 7:07:11 AM hudson.model.UpdateSite updateData
INFO: Obtained the latest update center data file for UpdateSource default
Feb 08, 2019 7:07:11 AM hudson.WebAppMain$3 run
INFO: Jenkins is fully up and running
=======================================================================
Best Practices for Writing Docker files:
Dockerfile is a step by step process by manually doing
FROM alpine:3.9
LABEL MAINTAINER="QT"
RUN apk update && apk add openjdk8
ENV JAVA_HOME="/usr/lib/jvm/"
ARG downloadlocation
ARG containerlocation
ADD $downloadlocation $containerlocation
EXPOSE 8088
CMD ["java","-jar",$containerlocation]
Now need to do manually:
------------------------
ubuntu@ip-172-31-2-125:~$ docker image pull alpine
Using default tag: latest
latest: Pulling from library/alpine
6c40cc604d8e: Pull complete
Digest: sha256:b3dbf31b77fd99d9c08f780ce6f5282aba076d70a513a8be859d8d3a4d0c92b8
Status: Downloaded newer image for alpine:latest
ubuntu@ip-172-31-2-125:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest caf27325b298 8 days ago 5.53MB
Now enter into the container:
ubuntu@ip-172-31-2-125:~$ docker container run -ti alpine
/ # pwd
/
/ # df -h
Filesystem Size Used Available Use% Mounted on
none 7.7G 3.0G 4.3G 41% /
tmpfs 64.0M 0 64.0M 0% /dev
tmpfs 496.2M 0 496.2M 0% /sys/fs/cgroup
/dev/xvda1 7.7G 3.0G 4.3G 41% /etc/resolv.conf
/dev/xvda1 7.7G 3.0G 4.3G 41% /etc/hostname
/dev/xvda1 7.7G 3.0G 4.3G 41% /etc/hosts
shm 64.0M 0 64.0M 0% /dev/shm
tmpfs 496.2M 0 496.2M 0% /proc/acpi
tmpfs 64.0M 0 64.0M 0% /proc/kcore
tmpfs 64.0M 0 64.0M 0% /proc/keys
tmpfs 64.0M 0 64.0M 0% /proc/latency_stats
tmpfs 64.0M 0 64.0M 0% /proc/timer_list
tmpfs 64.0M 0 64.0M 0% /proc/timer_stats
tmpfs 64.0M 0 64.0M 0% /proc/sched_debug
tmpfs 496.2M 0 496.2M 0% /proc/scsi
tmpfs 496.2M 0 496.2M 0% /sys/firmware
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
v3.9.0-15-gc85c9452e9 [http://dl-cdn.alpinelinux.org/alpine/v3.9/main]
v3.9.0-16-gfe0ab7c606 [http://dl-cdn.alpinelinux.org/alpine/v3.9/community]
OK: 9750 distinct packages available
/ # apk add openjdk8
(1/40) Installing libffi (3.2.1-r6)
(2/40) Installing p11-kit (0.23.14-r0)
(3/40) Installing libtasn1 (4.13-r0)
(4/40) Installing p11-kit-trust (0.23.14-r0)
(5/40) Installing ca-certificates (20190108-r0)
/ # java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (IcedTea 3.10.0) (Alpine 8.191.12-r0)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
# cd /usr/lib/jvm
/usr/lib/jvm # ls -ltr
total 4
drwxr-xr-x 6 root root 4096 Feb 8 07:23 java-1.8-openjdk
lrwxrwxrwx 1 root root 16 Feb 8 07:23 default-jvm -> java-1.8-openjdk
/usr/lib/jvm #
Comments
Post a Comment