Skip to content

Commit 82896c4

Browse files
author
sangam14
committed
Create Lab#7:RUN_instruction.md
1 parent 1ac1508 commit 82896c4

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Lab #7: RUN instruction
2+
3+
The `RUN` instruction execute command on top of the below layer and create a new layer. <br>
4+
RUN instruction can be wrote in two forms:
5+
- RUN <command> (shell form)
6+
- RUN ["executable", "param1", "param2"] (exec form)
7+
8+
## Pre-requisite:
9+
10+
## Tested Infrastructure
11+
12+
<table class="tg">
13+
<tr>
14+
<th class="tg-yw4l"><b>Platform</b></th>
15+
<th class="tg-yw4l"><b>Number of Instance</b></th>
16+
<th class="tg-yw4l"><b>Reading Time</b></th>
17+
18+
</tr>
19+
<tr>
20+
<td class="tg-yw4l"><b> Play with Docker</b></td>
21+
<td class="tg-yw4l"><b>1</b></td>
22+
<td class="tg-yw4l"><b>5 min</b></td>
23+
24+
</tr>
25+
26+
</table>
27+
28+
## Pre-requisite
29+
30+
- Create an account with [DockerHub](https://hub.docker.com)
31+
- Open [PWD](https://labs.play-with-docker.com/) Platform on your browser
32+
- Click on **Add New Instance** on the left side of the screen to bring up Alpine OS instance on the right side
33+
34+
## Assignment:
35+
36+
- Create an image with RUN instruction
37+
- Combining multiple RUN instruction to one
38+
39+
### Create an image with RUN instruction
40+
```
41+
FROM alpine:3.9.3
42+
LABEL maintainer="Collabnix"
43+
RUN apk add --update
44+
RUN apk add curl
45+
RUN rm -rf /var/cache/apk/
46+
```
47+
#### Building Docker image
48+
```
49+
$ docker image build -t run:v1 .
50+
```
51+
#### Checking layer of the image
52+
```
53+
$ docker image history run:v1
54+
IMAGE CREATED CREATED BY SIZE
55+
NT
56+
5b09d7ba1736 19 seconds ago /bin/sh -c rm -rf /var/cache/apk/ 0B
57+
192115cc597a 21 seconds ago /bin/sh -c apk add curl 1.55MB
58+
0518580850f1 43 seconds ago /bin/sh -c apk add --update 1.33MB
59+
8590497d994e 45 seconds ago /bin/sh -c #(nop) LABEL maintainer=Collabnix 0B
60+
cdf98d1859c1 4 months ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
61+
<missing> 4 months ago /bin/sh -c #(nop) ADD file:2e3a37883f56a4a27… 5.53MB
62+
```
63+
Number of layers 6
64+
65+
#### Checking image size
66+
```
67+
$ docker image ls run:v1
68+
REPOSITORY TAG IMAGE ID CREATED SIZE
69+
run v1 5b09d7ba1736 4 minutes ago 8.42MB
70+
```
71+
Its 8.42MB
72+
73+
### Combining multiple RUN instruction to one
74+
```
75+
FROM alpine:3.9.3
76+
LABEL maintainer="Collabnix"
77+
RUN apk add --update \ &&
78+
apk add curl \ &&
79+
rm -rf /var/cache/apk/
80+
```
81+
#### Building Docker image
82+
```
83+
$ docker image build -t run:v2 .
84+
```
85+
#### Checking layer of the image
86+
```
87+
$ docker image history run:v2
88+
IMAGE CREATED CREATED BY SIZE
89+
NT
90+
784298155541 50 seconds ago /bin/sh -c apk add --update && apk add curl… 1.55MB
91+
8590497d994e 8 minutes ago /bin/sh -c #(nop) LABEL maintainer=Collabnix 0B
92+
cdf98d1859c1 4 months ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
93+
<missing> 4 months ago /bin/sh -c #(nop) ADD file:2e3a37883f56a4a27… 5.53MB
94+
```
95+
Number of layers 4
96+
#### Checking image size
97+
```
98+
$ docker image ls run:v2
99+
REPOSITORY TAG IMAGE ID CREATED SIZE
100+
run v2 784298155541 3 minutes ago 7.08MB
101+
```
102+
its now 7.08MB
103+
104+
## Contributor
105+
[Savio Mathew](https://www.linkedin.com/in/saviovettoor)
106+
107+
Next » [Lab #8: ARG instruction](https://dockerlabs.collabnix.com/beginners/dockerfile/arg.html)

0 commit comments

Comments
 (0)