Skip to content

Commit 8fb25b3

Browse files
Add running docker image info
1 parent e49c730 commit 8fb25b3

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

README.md

+20-18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This is just a simple demonstration to get a basic understanding of how docker w
1717
- [Setting up your machine](#setting-up-your-machine)
1818
- [Writing your first Dockerfile](#writing-your-first-dockerfile)
1919
- [Building your Docker Images](#building-your-docker-images)
20+
- [Running the docker image](#running-the-docker-image)
2021
- [Understanding Docker images and image layers](#understanding-docker-images-and-image-layers)
2122
- [Using image tags effectively](#using-image-tags-effectively)
2223

@@ -75,7 +76,6 @@ console.log('Server running at http://127.0.0.1:8888/');
7576
2. Create a file named `Dockerfile` and copy this code into it.
7677

7778
```bash
78-
// Extract
7979
FROM node:8
8080

8181
LABEL maintainer="[email protected]"
@@ -91,7 +91,7 @@ ENTRYPOINT [ "node", "hello.js" ]
9191

9292
Even if this is the first Dockerfile you’ve ever seen, I’d say you could have a good guess what’s happening here. The Dockerfile instructions are FROM, ENV, LABEL, RUN , ADD , EXPOSE and ENTRYPOINT; they’re in capitals but that’s a convention, not a requirement.
9393

94-
At a high-level, this Dockerfile gives instructions like: Start with the node image, add “[email protected]” as the maintainer, run `npm install` to install dependencies, copy file in the application code, document the app’s network port, and set hello.js as the default application to run.
94+
At a high-level, this Dockerfile gives instructions like: Start with the node image, add `[email protected]` as the maintainer, run `npm install` to install dependencies, copy file in the application code, document the app’s network port, and set hello.js as the default application to run.
9595

9696
#### Building your Docker Images
9797

@@ -103,16 +103,23 @@ docker build -t helloworld .
103103

104104
Here you’re telling Docker to build an image called `helloworld` based on the contents of the current directory (note the **dot (.)** at the end of the build command). Docker will look for the Dockerfile in the directory and build the image based on the instructions in the file.
105105

106-
Now check your docker image created by running
106+
#### Running the docker image
107+
108+
After building the docker image , next step would be run the image and see if it actually works:
107109

108110
```bash
109-
docker image history helloworld
110-
IMAGE CREATED CREATED BY COMMENT
111-
cb84eb33ca20 58 seconds ago /bin/sh -c #(nop) ENTRYPOINT ["node" "hello…
112-
7d652a817a9f 58 seconds ago /bin/sh -c #(nop) EXPOSE 8888
113-
334575e947c9 59 seconds ago /bin/sh -c #(nop) ADD file:b9606ef53b832e66e…
111+
docker run -p 8888:8888 helloworld
114112
```
115113

114+
The command we just ran used port 8888 for the server inside the container and exposed this externally on port 8888. Head over to the URL with port 8888:
115+
116+
<p align="center">
117+
<img src="./local_resources/locahost.jpg" />
118+
</p>
119+
120+
Congrat! You have successfully created your first docker image.
121+
122+
116123
#### Understanding Docker images and image layers
117124

118125
Docker images are like virtual machine templates and are used to start containers. Under the hood they are made up one or more read-only layers, that when stacked together, make up the overall image. Docker takes care of stacking these layers and representing them as a single unified object. **Note:** Docker Images are immutable means Docker images can’t ever change. Once you’ve made one, you can delete it, but you can’t modify it.
@@ -124,16 +131,11 @@ Docker images are like virtual machine templates and are used to start container
124131
The Docker image contains all the files you packaged, which become the container’s filesystem - and it also contains a lot of metadata about the image itself. That includes a brief history of how the image was built. You can use that to see each layer of the image, and the command that built the layer. You can check history of `helloworld` image by using:
125132

126133
```bash
127-
docker image history helloworld
128-
IMAGE CREATED CREATED BY SIZE
129-
cb84eb33ca20 6 days ago /bin/sh -c #(nop) ENTRYPOINT ["node" "hello… 0B
130-
7d652a817a9f 6 days ago /bin/sh -c #(nop) EXPOSE 8888 0B
131-
334575e947c9 6 days ago /bin/sh -c #(nop) ADD file:b9606ef53b832e66e… 189B
132-
45b27540538e 2 weeks ago /bin/sh -c npm i 432B
133-
8eeadf3757f4 4 months ago /bin/sh -c #(nop) CMD ["node"] 0B
134-
<missing> 4 months ago /bin/sh -c #(nop) ENTRYPOINT ["docker-entry… 0B
135-
<missing> 4 months ago /bin/sh -c #(nop) COPY file:238737301d473041… 116B
136-
<missing> 4 months ago /bin/sh -c set -ex && for key in 6A010… 5.48MB
134+
docker image history helloworld
135+
IMAGE CREATED CREATED BY COMMENT
136+
cb84eb33ca20 58 seconds ago /bin/sh -c #(nop) ENTRYPOINT ["node" "hello…
137+
7d652a817a9f 58 seconds ago /bin/sh -c #(nop) EXPOSE 8888
138+
334575e947c9 59 seconds ago /bin/sh -c #(nop) ADD file:b9606ef53b832e66e…
137139
```
138140

139141
The `CREATED BY` commands are the Dockerfile instructions – there’s a one-to-one relationship, so each line in the Dockerfile creates an image layer.

hello.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ var http = require("http");
22

33
http.createServer(function (request, response) {
44
response.writeHead(200, {'Content-Type': 'text/plain'});
5-
response.end('Hello World\n');
5+
response.end('Hello World from Docker\n');
66
}).listen(8888);

local_resources/locahost.jpg

27.9 KB
Loading

0 commit comments

Comments
 (0)