-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdockercommand.txt
More file actions
164 lines (147 loc) · 7.07 KB
/
dockercommand.txt
File metadata and controls
164 lines (147 loc) · 7.07 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
docker run <image name> - your container will be created
docker run -d <image name> - runs your image in detached mode
docker ps -- running container
docker ps -a -- all containers (exited running)
docker ps -q -- all the container ids (running)
docker ps -qa -- all containers ids (exer run --name anup ited running)
docker run -d name containernam imagename - gives auth name to your container (while cont is running)
docker rename (cont id 809) (newname of cont b24) - to rename exiting cont
docker start <container id> - to start the container
docker stop <container id> - to stop the container
docker rm <container id> - to remove container
docker exec -it <container id> bash - can enter into existing container or run any command in it.
docker exec <container id> command - without goin inside container you can execute command inside it
docker run -it <image name> command(bash or sh) - can enter inside container or can execute any command into cont
docker run <image name> <command> - can execute command in running container
docker stats container_id - will give you container stats
docker inspect container_id
port mapping
docker run -p -d 80:80 nginx --- will port map with container's port with hosts port
docker run -d -P nginx -- will give map with container's port with hosts random port
docker cp source destination - copies file from source to destination
docker cp source file container_id:/usr/local/nginx/html/index.html
/usr/local/apache2/htdocs/html/index.html
docker rm -f `docker ps -qa` - will remove all container at once
docker rmi -rf `docker ps -qa` - will remove all images
docker logs containerid - logs of container
docker stats containerid - docker conatainer stats
docker top containerid - docker container id top process viewer
#docker rmi -f $(docker images -q) - will delete all images at once
#docker rm -f $(docker ps -a -q) - will delete all container at once
docker run = pull + create + save
DOCKER IMAGES
172.17.0.2
docker build Dockerfilelocation - builds docker image
basic syntax of docker file -
----------------------------------
INSTRUCTION arguments
-----------------------------------
LABEL KEY = VALUE - gives metadata ,label ,identity ,labels are visible by docker inspect
for eg
LABEL devops = "Anup"
----------------------------------
FROM baseimagename - provides a baseimage on which layers are created or ran
for eg
FROM centos:7
--------------------------------
RUN command - Run instruction to start and create the required file structure
that you need and install some required software dependencies
for eg
RUN yum install httpd -y
--------------------------------
EXPOSE port - exposing the container to a port
for eg
EXPOSE 80
--------------------------------
CMD defines the command that launches the process , that you want to run within container
for eg- can be overridden , replced as well
CMD ["executable","param1","param2"]
CMD ["httpd" , "-DFOREGROUND"]
CMD command param1 param2
CMD httpd -DFOREGROUND
----------------------------------
WORKDIR - you can change the working directory in the image for remainig build instructions
WORKDIR pathhway of destination
----------------------------------
COPY - is used to copy files from the local system into your image.
COPY source destination
-----------------------------------
ADD - is used when you want to retrieve data from remote location into your image and
container.
ADD source destination
-----------------------------------
USER
USER root - preferance of user can be performed using this argument.
-----------------------------------
ENTRYPOINT - the mentioned executable using Entrypoint.
by default the mentioned executable will and can be replace only and only by
sudo docker run --entrypoint [new_command] [docker_image] [optional:value] , i.e
entrypoint flag only.
ENTRYPOINT ["executable" , "param1"]
ENTRYPOINT executable param1 param2
------------------------------------
HEALTHCHECK - checking health of container on startup
------------------------------------
SOURCE - H/W
------------------------------------
ENV - to pass variables
-------------------------------------
ARG - to pass enviornment variables
ARG <name>[=<default value>]
-------------------------------------
SHELL - set default shell to image
SHELL SHELL ["powershell", "-command"]
---------------------------------------
volume
volume [/mnt] - create volume mounts
---------------------------------------
STOPSIGNAL - kind of working like kill -9 will stop the container process.
---------------------------------------
ONBUILD - to provide instruction during when image is used in build.
ONBUILD instruction
ONBUILD RUN echo "this image is now built"
ONBUILD RUN yum install httpd -y
------------------------------------------------------------
Docker Network
DOCKER network drivers or docker network types
bridge - to connect two different networks , create bridge between two diff networks.
(eg communication between host and docker container is possible because of bridge)
overlay - to communicate two containers that are present in two seprate networks(hosts) using
docker swarm.
none - doesnt have any ip attached to it to keep your container completely isolated and
ensure this container is kept as a backup container.
host - the container will get host ip that is localhost ip
macvlan - to give physical identity , to make appear as physical ,allocating physical
address to container
IPvlan - we use this network to provide ipv4 and ipv6 addresss of our choice or
assign customize ip to container,i.e take control over ipv4 or ipv6 assigning.
Dockernetwork commands
docker network create --subnet "192.168.0.0/16" --driver bridge newnetwork
docker network ls
docker run -d -P --network newnetwork nginx
docker run -d -p --network host httpd
docker run -d -p --network <network_driver_type> image name
-----------------------------------------------------------------------
Docker Volume
docker volume ls
docker volume create newvol1
docker run -d -p -v newvol1:/usr/local/apache2/htdocs/ httpd
docker run -d -p -v newvol1:/usr/share/nginx/html/ nginx
root dir location - /var/lib/docker/volumes
mkdir /mnt/voldir
docker -d -p -v /mnt/voldir:/usr/local/tomcat/ tomcat
-----------------------------------------------------------------
Docker Compose
basic command to run docker Compose
A compose file will ensure that you dont need to run commands and its configurations
over and over you just need to have a config file and using that file you will keep on building
you containers.
docker compose up . - where your compose file is present
docker compose down .
docker compose prune
-------------------------------------------------------------------
Docker registory
docker login
docker tag imagename dockerhubusername/repositoryname:tag #image name and repo name should be same
docker run username/nameofrepo:tag
docker image push anupdudhe/dockercomposenginx-frontendnginxfirst:latest