forked from vikas99341/node-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd
More file actions
186 lines (146 loc) · 5.95 KB
/
cmd
File metadata and controls
186 lines (146 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
python2.7
yum install pip
pip install numpy
python <code name>
Python 3.7
#Download get-pip to current directory. It won't install anything, as of now
curl -O https://bootstrap.pypa.io/get-pip.py
#Use python3.6 to install pip
python3 get-pip.py
#this will install pip3 and pip3.6
yum install pip3
pip3 install numpy
python3 <code name>
Dockerfile -- > Images -- > Conatiner
docker inspect <container-id>
docker logs -f <container-id>
docker exec -it <container-id> /bin/bash
Dangling Image - Images who have no owner /orphan images
docker system prune
Remove a Image
===============
docker rmi <Image_id>
Remove a Container
==================
docker rm -f <Container_id>
docker ps -a == > show me all the container
===========================================
docker run -it --name python-app <>
docker stop <>
docker start -a -i <>
docker image prune - Unsed images are removed
docker run --rm == > remove the container once it's stopped
docker image inspect <> == > Details of the image
docker cp <on local> <container_name:/test> == > copy from local to inside container
Docker Volume : Data preservation methodology
================================
docker volume ls
docker volume create volume vol1
docker volume inspect <volume name> -- > by default storage is /var/lib/docker
docker run -it --name <any name> -v <volume on container>:<directory on host> <container id> == > docker run –it --name container1 –v vol1:/data ubuntu
this volume can be attached to multiple containers.
docker volume rm vol1
Bind Mount : Another way to share container data with host machine with location choice
===========================================================
cd tmp/logs -- > create a file.txt -- >
docker run –it –name <container name> -v /tmp/logs:/data:Z <image name>
/tmp/logs in host machine is mapped to /data on container .
Create a dockerfile :
=============
FROM ubuntu
Maintainer “Vikas”
RUN apt-get update
RUN apt-get install vim –y
CMD /bin/echo “Hello from Docker”
docker build –t <image name required> .
docker images to check the image created
Docker Network:
============
docker network ls -- > see the default networks
1. bridge 2. host 3. null
docker network inspect bridge -- > check the containers section
Different containers under same network can talk with each other via ip address
apt-get update && apt-get install –y iputils-ping
take one of the the container ip from inspect command and use it on the other one to see connectivity .
Create a custom bridge :
===============
docker network create --driver bridge <bridge name>
docker run -itd --name <container name> --network <network created > <image from hub>
Port Publishing or forwarding on Docker:
===========================
docker run -itd --name <container name> nginx
docker inspect <container name> -- > to get the IPAddress
curl ip:80 -- > get the o/p
docker run -itd --name <container name> -P nginx
docker run -itd --name <container name> -p 9999:80 nginx
Docker file is a blueprint for building image
Keywords:
FROM : Talks about the base image
ENV : Optional as environment variables are defined here .
RUN - Execute any Linux command .Execution will happen inside the container .
COPY - Source can be local, and destination is inside container
CMD – Always part of docker file . Execute entry point Linux command .
Multiple RUN commands can be there but only one CMD command .
Docker Network :
https://www.docker.com/blog/understanding-docker-networking-drivers-use-cases/
https://docs.docker.com/network/
docker network ls
docker network --help
docker network ls -f driver=bridge
docker network ls --format "{{.ID}}: {{.Driver}}"
docker network inspect "networkid"
docker network create "networkname"
docker network create -d bridge "networkname“
docker network rm “networkname”
docker network connect "networkname" "containername"
docker container run -d --name "nameofcontainer" --network "networkname" image
docker network disconnect "networkname" "containername“
Docker exec –it nginx1 bash
apt-get update
apt-get install iputils-ping
docker exec -it “nginx2" ping “nginx3"
Install docker on amazon linux :
-------------------------------
yum install docker –y
Common commands:
-------------------------
docker pull ubuntu
docker images / docker image ls
docker run –it –d ubuntu -- > attached to a container it should be in running mode .
docker ps –a /docker ps
docker run -d --name test-tomcat-server -p 8090:8080 tomcat:latest
docker exec –it <container_id> bash
docker kill <container_id>
docker rm <container id> -- > will remove the container but it should be stopped
docker rm -f <container_id> -- > delete container forcefully
docker rmi <image id> -- > to remove the image
docker rm –f $(docker ps –a –q )
docker commit
docker start <container id >
docker stop <contain ner id >
come out of atatched mode -- > ctrl +p .ctrl +q
root@df33de3dcefb:/usr/local/tomcat/webapps.dist# cp -R * ../webapps
docker exec -it tomcat-vikas /bin/bash
Create a volume to preserve the data present in container :
----------------------------------------------------------
docker volume ls -- > list
docker volume create vol1 -- > create a volume
docker volume inspect vol1 -- > see the location
docker run -it --name <any name> -v vol1:/data <container name>
docker volume rm vol1
Bind Mount :
-----------
docker run -it --name <any name> -v <bind mount location eg: /tmp/logs>:/data:Z Ubuntu -- > this Z flag will enable read write in container .
docker run -it --name <any name> --volumes-from <existing container name > Ubuntu
Docker Installation on Ubuntu machine :
--------------------------------------------
sudo apt-get update
sudo apt-get install docker.io
dockerfile :
------------
From ubuntu
Maintainer “Vikas”
RUN apt-get update
RUN apt-get install vim –y
CMD /bin/echo “ I am from ubuntu container “
To run this, say == > docker build –t myimage .