Skip to content

Commit d473232

Browse files
committed
Abstracted build argument in dockerfile, added docker instructions and ignore file
1 parent 9abc115 commit d473232

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

apps/frontend/.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
.dockerignore
3+
.git
4+
.gitignore
5+
.next
6+
out
7+
public
8+
README.md

apps/frontend/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
FROM node:18-alpine AS base
22

33
# For now we can specify it here, else we can use --build-arg in our docker build command
4-
ENV NEXT_PUBLIC_API_URL="http://localhost:8080/"
4+
ARG NEXT_PUBLIC_API_URL
5+
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
56

67
# Install dependencies only when needed
78
FROM base AS deps

apps/frontend/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,20 @@ You can start editing the page by modifying `app/page.tsx`. The page auto-update
4242
# Navigate to the frontend app directory
4343
cd apps/frontend
4444
# Build dockerfile (Ensure that your docker daemon is running beforehand)
45-
docker build -t frontend -f Dockerfile .
45+
docker build -t frontend --build-arg NEXT_PUBLIC_API_URL="http://localhost:8080/" -f Dockerfile .
4646
```
4747

4848
Run the backend server locally and visit http://localhost:3000/ to see the frontend application working
49+
50+
## Running Docker Image
51+
52+
```sh
53+
# Run the docker image, the -d tag is to run it detached
54+
docker run -p 3000:3000 -d frontend
55+
56+
# To see the running container
57+
docker ps
58+
59+
# To stop the container, copy the container id from the previous command
60+
docker stop <container_id>
61+
```

0 commit comments

Comments
 (0)