Skip to content

Commit abd3311

Browse files
authored
Merge pull request #4 from AldrionDev/task-2-dockerize-http-server
Dockerize Go HTTP server
2 parents 26c0824 + 21ec04c commit abd3311

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.git
2+
.github
3+
.gitignore
4+
README.md
5+
Dockerfile
6+
.dockerignore
7+
8+
*.log
9+
tmp/
10+
dist/
11+
bin/
12+
coverage.out

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -------Build stage-------
2+
FROM golang:1.26-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
COPY go.mod ./
7+
COPY *.go ./
8+
9+
RUN CGO_ENABLED=0 GOOS=linux go build -o http-server .
10+
11+
12+
# -------Runtime stage-------
13+
FROM alpine:3.23
14+
15+
WORKDIR /app
16+
17+
COPY --from=builder /app/http-server .
18+
19+
EXPOSE 8080
20+
21+
CMD ["./http-server"]

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ http-server-devops/
3030
## Tasks
3131

3232
- [x] Task 1: HTTP Server
33-
- [ ] Task 2: Dockerize
33+
- [x] Task 2: Dockerize
3434
- [ ] Task 3: CI/CD Pipeline
3535
- [ ] Task 4: Kubernetes Deployment
3636
- [ ] Task 5: Terraform Configuration
@@ -64,3 +64,33 @@ Run tests:
6464
```bash
6565
go test ./...
6666
```
67+
68+
## Docker Usage
69+
70+
### Build image
71+
72+
```bash
73+
docker build -t http-server-devops:local .
74+
```
75+
76+
### Run container
77+
78+
```bash
79+
docker run --rm -p 8080:8080 http-server-devops:local
80+
```
81+
82+
### Test container
83+
84+
```bash
85+
curl http://localhost:8080/
86+
```
87+
88+
### Run with custom port
89+
90+
```bash
91+
docker run --rm -p 9090:9090 -e PORT=9090 http-server-devops:local
92+
```
93+
94+
```bash
95+
curl http://localhost:9090/
96+
```

0 commit comments

Comments
 (0)