Skip to content

Commit 0943294

Browse files
added owasp-juice-shop-launch-with-own-docker-image
1 parent d45f899 commit 0943294

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
title: owasp juice shop > launch with own docker image
3+
categories: owasp juice shop
4+
---
5+
6+
There is already an offical docker image for the juice shop application at the repo
7+
bkimminich/juice-shop. However we also have the provision to make a docker image of our own, using the
8+
docker file in the source code, as the juice shop is an open source application. In this blog post,
9+
we are gonna see how to do that. Its assumed you have cloned the source code of juice shop from github,
10+
you have installed docker on your system, and you have an account at docker hub.
11+
12+
Let's get started...
13+
14+
I'm at the root of the repo.
15+
```
16+
$ pwd
17+
/home/networkandcode/juice-shop
18+
```
19+
20+
There should be a Dockerfile at this directory.
21+
```
22+
$ ls Dockerfile
23+
Dockerfile
24+
```
25+
26+
Let's view the contents of this Dockerfile.
27+
```
28+
$ cat Dockerfile
29+
FROM node:12 as installer
30+
COPY . /juice-shop
31+
WORKDIR /juice-shop
32+
RUN npm i -g typescript ts-node
33+
RUN npm install --production --unsafe-perm
34+
RUN npm dedupe
35+
RUN rm -rf frontend/node_modules
36+
37+
FROM node:12-alpine
38+
ARG BUILD_DATE
39+
ARG VCS_REF
40+
LABEL maintainer="Bjoern Kimminich <[email protected]>" \
41+
org.opencontainers.image.title="OWASP Juice Shop" \
42+
org.opencontainers.image.description="Probably the most modern and sophisticated insecure web application" \
43+
org.opencontainers.image.authors="Bjoern Kimminich <[email protected]>" \
44+
org.opencontainers.image.vendor="Open Web Application Security Project" \
45+
org.opencontainers.image.documentation="https://help.owasp-juice.shop" \
46+
org.opencontainers.image.licenses="MIT" \
47+
org.opencontainers.image.version="12.8.1" \
48+
org.opencontainers.image.url="https://owasp-juice.shop" \
49+
org.opencontainers.image.source="https://github.com/bkimminich/juice-shop" \
50+
org.opencontainers.image.revision=$VCS_REF \
51+
org.opencontainers.image.created=$BUILD_DATE
52+
WORKDIR /juice-shop
53+
RUN addgroup --system --gid 1001 juicer && \
54+
adduser juicer --system --uid 1001 --ingroup juicer
55+
COPY --from=installer --chown=juicer /juice-shop .
56+
RUN mkdir logs && \
57+
chown -R juicer logs && \
58+
chgrp -R 0 ftp/ frontend/dist/ logs/ data/ i18n/ && \
59+
chmod -R g=u ftp/ frontend/dist/ logs/ data/ i18n/
60+
USER 1001
61+
EXPOSE 3000
62+
CMD ["npm", "start"]
63+
```
64+
65+
From the dockerfile, we see its base image is node12:alpine which will be picked from dockerhub, and
66+
then its executing certain linux commands, we are not gonna get into the depth of those commands, here
67+
though. Finally it runs the command npm start, to start the juice shop application.
68+
69+
Let's build our docker image using this dockerfile. The format of the command would be ```docker build .
70+
-t <username/repo:tag>``` Here ```.``` refers to the current directory as we are going to run this command where
71+
the dockerfile is present. The username is your docker hub username, I have used my username which is
72+
s1405. The tag if not provided will be latest by default.
73+
```
74+
$ docker build . -t s1405/owasp-juice-shop:21080813
75+
Sending build context to Docker daemon 46.23MB
76+
Step 1/18 : FROM node:12 as installer
77+
12: Pulling from library/node
78+
08224db8ce18: Pull complete
79+
abd3caf86f5b: Pull complete
80+
71c316554a55: Pull complete
81+
--TRUNCATED--
82+
Successfully built ef2e35d02cce
83+
Successfully tagged s1405/owasp-juice-shop:21080813
84+
```
85+
86+
The image is successfully built.
87+
```
88+
$ docker image ls s1405/owasp-juice-shop
89+
REPOSITORY TAG IMAGE ID CREATED SIZE
90+
s1405/owasp-juice-shop 21080813 ef2e35d02cce 13 minutes ago 495MB
91+
```
92+
93+
We can push this image to our docker hub repo, for which we need to login first.
94+
```
95+
$ docker login
96+
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
97+
Username: s1405
98+
Password:
99+
WARNING! Your password will be stored unencrypted in /home/networkandcode/snap/docker/796/.docker/config.json.
100+
Configure a credential helper to remove this warning. See
101+
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
102+
103+
Login Succeeded
104+
```
105+
106+
And then push. This stage is optional, however it helps with reusing the image in future, when not
107+
available locally.
108+
```
109+
$ docker push s1405/owasp-juice-shop:21080813
110+
The push refers to repository [docker.io/s1405/owasp-juice-shop]
111+
3661f3683042: Pushed
112+
1dbe1865b615: Pushed
113+
3548ffb57dd8: Layer already exists
114+
f166ad2b7b2d: Layer already exists
115+
052597e22e57: Layer already exists
116+
b5d9fcff4e03: Layer already exists
117+
a96e37fcd4d5: Layer already exists
118+
9a5d14f9f550: Layer already exists
119+
21080813: digest: sha256:8908216d39a2937c16c61ad7b4f65e30aa1e239adea08c1e26c15b9c827b8d7d size: 1999
120+
```
121+
122+
The image should appear on docker hub too.
123+
![OWASP Juice Shop Image](/assets/owasp-juice-shop-launch-with-own-docker-image-1.png)
124+
125+
We can now run the app with our docker image.
126+
```
127+
$ docker run -d -p 8000:3000 s1405/owasp-juice-shop:21080813
128+
922fb0c8729f21ac649185246c2134f52c69f4cd920fad926e48dfbf3c0638ac
129+
```
130+
131+
It wont pull the image from docker hub, as the image is already there locally, we have however pushed
132+
it to docker hub, so that we can use it in future when required.
133+
134+
The container is active.
135+
```
136+
$ docker container ls | grep juice-shop
137+
922fb0c8729f s1405/owasp-juice-shop:21080813 "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:8000->3000/tcp bold_mahavira
138+
```
139+
140+
We can access the app on our browser.
141+
![OWASP Juice Shop Image](/assets/owasp-juice-shop-launch-with-own-docker-image-2.png)
142+
143+
Stop the container when required.
144+
```
145+
$ docker container stop 922fb0c8729f
146+
922fb0c8729f
147+
```
148+
149+
Hope this post helps in building your own docker image version of the juice shop app, pushing it to
150+
your docker hub registry and running a container with the image. Thank you for reading.
151+
152+
--end-of-post--
42.2 KB
Loading
66.7 KB
Loading

0 commit comments

Comments
 (0)