Day - 1
yum install docker @@ install docker
systemctl restart docker @@ restart docker
systemctl enable docker @@ autostart docker if machine restart
docker version
docker images @@ List all the images in local
docker ps @@ list the running container
docker ps -a @@ list all the container
docker run <image> @@ Starting a new container of image
docker run -i -t ubuntu /bin/bash @@ Give me interactive terminal of ubuntu image container
docker run -d smehta26/clock @@container run without log or detached
docker logs <containerId or containerName> @@print the logs
docker logs --tail 3 <containerId or containerName> @@print only 3 lines of logs
docker logs --tail 1 --follow <containerId or containerName> @@follow the logs
Starting container with user specific command
docker run -d ubuntu:14:04 sleep 1000000
Get inside the container
docker exec -it <containerId> bash
ps -eaf @@check the process once inside the container
docker exec -it <containerId> sh
Name the container
docker run -d --name c1 ubuntu:14.04 sleep 1000
docker run -d --name c2 ubuntu:14.04 sleep 1000
docker stop c1 @@graceful stop takes times
docker kill c2 @@forceful stop immediate
docker start c1
docker start c2
docker stop C1 @@Stop the container
docker start C1 - @@Start the container
docker kill C1 @@kill the container
docker rm C1 @@Remove the container
Inspect running container
docker inspect c1
Kill and remove all the running container
docker ps -q @@give only running containerId
docker ps -aq @@gives all the containerId
docker kill $(docker ps -q); docker rm $(docker ps -aq) @@kill all the running container & remove all container
CREATE YOUR OWN IMAGE:
open vi editor DockerFile and type below command
#FROM instruction is used ot define Base OS Image.
FROM ubuntu:14.04
#RUN instruction to execute command over previous step
RUN apt-get update
RUN apt-get install figlet
#CMD instruction to define default command which will run when container starts
CMD figlet zpaya
Save the editor
[root@master]# docker build -t figlet:1.0 .
[root@master]# docker images
[root@master]# docker history figlet:1.0
[root@master]# docker run figlet:1.0
[root@master]# docker ps -a --no-trunc
[root@master]# docker run figlet:1.0 figlet docker
[root@master]# docker ps -a --no-trunc
Create a image with custome file:
open vi editor Customfile and type below command
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install figlet
#ENTRYPOINT instruction is there to define default command which will run when container starts
ENTRYPOINT ["figlet"]
Save the file and build the figlet:2.0 image and start the container with the image.
COPY:
open vi editor, copy from docker host to the container
COPY Customfile /etc/
COPY Dockerfile /tmp/
Save the file and build the figlet:3.0 image and start the container with the image.
[root@master-]# docker build -t figlet:3.0 -f abc1 .
[root@master-]# docker run -it figlet:3.0 bash
root@81c9:/# cat /etc/abc
root@81c9:/# cat /tmp/Dockerfile
ENVIRONMENT VARIABLES:
vi Env
FROM ubuntu:14.04
ENV blog Blogger
ENV maven /usr/bin/mvn
ENV JAVA_HOME /usr/bin/java
CMD echo "$blog $maven $JAVA_HOME"
[root@master-]# docker build -t figlet:4.0 -f abc1 .
[root@master-]# docker run -it figlet:4.0 bash
USER INSTRUCTION:
vi UserInstruction
FROM ubuntu:14.04
RUN useradd -d "/home/zpaya" -m -s "/bin/bash" zpaya
USER zpaya
CMD id
Save the file
[root@master-]# docker build -t figlet:5.0 -f abc1 .
[root@master-]# docker run -it figlet:5.0 bash
EXPOSE PORT to INTERNET:
docker run -d -P nginx @@Expose the random port of nginx to Master node
docker run -d -p 1000:80 nginx @@Expose specified port of nginx(80) to masternode
ifconfig eth0 @@will give you the public.
http://139.xx.73.xx:1000/
Day - 2
docker push Z - upload the container
Code(Dockerfile) —>
compile(docker build) —>
DockerImage
No comments:
Post a Comment