Skip to content

Commit 8d58b66

Browse files
arun-guptarafabene
authored andcommitted
1 parent fea63e4 commit 8d58b66

1 file changed

Lines changed: 58 additions & 56 deletions

File tree

chapters/docker-image.adoc

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,21 @@ _Dockerfile_ is usually called _Dockerfile_. The complete list of commands that
2626

2727
=== Create your first Docker image
2828

29-
Create a new text file _Dockerfile_ in an empty directory and use the following contents:
30-
31-
.Hello World Dockerfile
29+
. Create a new directory.
30+
. Create a new text file, name it _Dockerfile_, and use the following contents:
31+
+
3232
[source, text]
3333
----
3434
FROM ubuntu
3535
3636
CMD ["/bin/echo", "hello world"]
3737
----
38-
38+
+
3939
This image uses `ubuntu` as the base image. `CMD` command defines the command that needs to run. It provides a different entry point of `/bin/echo` and gives the argument "`hello world`".
40-
41-
Build this image as:
42-
43-
[source, text]
44-
----
40+
+
41+
. Build this image:
42+
+
43+
```console
4544
> docker build -t helloworld .
4645
Sending build context to Docker daemon 2.048 kB
4746
Step 0 : FROM ubuntu
@@ -57,75 +56,80 @@ Step 1 : CMD /bin/echo hello world
5756
---> e81a394f71e3
5857
Removing intermediate container 132bb0bf823f
5958
Successfully built e81a394f71e3
60-
----
61-
62-
List the images available:
63-
64-
[source, text]
65-
----
59+
```
60+
+
61+
`.` in this command is the context for `docker build`.
62+
+
63+
. List the images available:
64+
+
65+
```console
6666
> docker images
6767
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
6868
helloworld latest 9c0e7b56cbee 13 minutes ago 187.9 MB
69-
----
70-
71-
Run the container:
72-
69+
```
70+
+
71+
. Run the container:
72+
+
7373
docker run -it helloworld
74-
74+
+
7575
to see the output:
76-
76+
+
7777
hello world
78-
79-
Change the base image from `ubuntu` to `busybox`, build the image again:
80-
78+
+
79+
. Change the base image from `ubuntu` to `busybox` in `Dockerfile`. Build the image again:
80+
+
8181
docker build -t helloworld2 .
82-
83-
[source, text]
84-
----
82+
+
83+
and view the images as:
84+
+
85+
```console
8586
> docker images
8687
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
8788
helloworld latest e81a394f71e3 26 minutes ago 187.9 MB
8889
helloworld2 latest c458787fadcf 3 seconds ago 1.113 MB
8990
ubuntu latest a5a467fddcb8 2 days ago 187.9 MB
9091
busybox latest 3d5bcd78e074 4 days ago 1.113 MB
91-
----
92+
```
9293

93-
=== Run WildFly
94-
95-
Create a new text file _Dockerfile_ in an empty directory and use the following contents:
94+
=== WildFly Image
9695

96+
. Create a new directory.
97+
. Create a new text file, name it _Dockerfile_, and use the following contents:
98+
+
9799
[source, text]
98100
----
99101
FROM jboss/wildfly
100102
----
101-
102-
Build the image:
103-
103+
+
104+
. Build the image:
105+
+
104106
docker build -t mywildfly .
105-
106-
Run the container:
107-
107+
+
108+
. Run the container:
109+
+
108110
docker run -it mywildfly
109111

110-
=== Deploy Java EE 7 Application
111-
112-
Create a new text file _Dockerfile_ in an empty directory:
112+
=== Java EE 7 Application Image
113113

114+
. Create a new directory.
115+
. Create a new text file, name it _Dockerfile_, and use the following contents:
116+
+
114117
[source, text]
115118
----
116-
FROM jboss/wildfly
119+
FROM jboss/wildfly <1>
117120
118-
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-c", "standalone-full.xml", "-b", "0.0.0.0"]
121+
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-c", "standalone-full.xml", "-b", "0.0.0.0"] <2>
119122
120-
RUN curl -L https://github.com/javaee-samples/javaee7-hol/raw/master/solution/movieplex7-1.0-SNAPSHOT.war -o /opt/jboss/wildfly/standalone/deployments/movieplex7-1.0-SNAPSHOT.war
123+
RUN curl -L https://github.com/javaee-samples/javaee7-hol/raw/master/solution/movieplex7-1.0-SNAPSHOT.war -o /opt/jboss/wildfly/standalone/deployments/movieplex7-1.0-SNAPSHOT.war <3>
121124
----
122-
123-
Three things happen in this image:
124-
. Uses "`jboss/wildfly`" as the base image
125-
. Starts WildFly application server in Full Platform mode
126-
. Copies the WAR file from from a URL to the deployment directory of WildFly
127-
128-
Build the image:
125+
+
126+
Three things in this image:
127+
+
128+
<1> Uses "`jboss/wildfly`" as the base image
129+
<2> Starts WildFly application server in Full Platform mode
130+
<3> Copies the WAR file from from a URL to the deployment directory of WildFly
131+
+
132+
. Build the image:
129133

130134
docker build -t movieplex .
131135

@@ -139,23 +143,21 @@ Default entry point for a container is `/bin/sh`, the default shell.
139143

140144
Running a container as `docker run -it ubuntu` uses that command and starts the default shell. The output is shown as:
141145

142-
[source, text]
143-
----
146+
```console
144147
> docker run -it ubuntu
145148
root@88976ddee107:/#
146-
----
149+
```
147150

148151
`ENTRYPOINT` allows to override the entry point to some other command, and even customize it. For example, a container can be started as:
149152

150-
[source, text]
151-
----
153+
```console
152154
> docker run -it --entrypoint=/bin/cat ubuntu /etc/passwd
153155
root:x:0:0:root:/root:/bin/bash
154156
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
155157
bin:x:2:2:bin:/bin:/usr/sbin/nologin
156158
sys:x:3:3:sys:/dev:/usr/sbin/nologin
157159
. . .
158-
----
160+
```
159161

160162
This command overrides the entry point to the container to `/bin/cat`. The argument(s) passed to the CLI are used by the entry point.
161163

0 commit comments

Comments
 (0)