Skip to content

Commit 25e85ad

Browse files
committed
feat: add demo for mongo-express
add demo for mongo-express add demo for mongo-express
0 parents  commit 25e85ad

11 files changed

+169
-0
lines changed

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
go.work.sum
23+
24+
# env file
25+
.env

README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# docker compose learning
2+
3+
This repository is for demo how to use docker compose
4+
5+
6+
## demo with mongo and mongo-express
7+
8+
### 1 architecture diagram
9+
10+
![architecture](architecture.png)
11+
12+
### 2 with docker command
13+
14+
1. create bridge network for container communication
15+
16+
```shell
17+
docker network create mongo-network
18+
```
19+
20+
![network-created](network-created.png)
21+
22+
2. ls current network created
23+
24+
```shell
25+
docker network ls
26+
```
27+
![network-ls](network-ls.png)
28+
29+
3. run mongo over mongo-network
30+
31+
```shell
32+
docker run -d \
33+
-p 27017:27017 \
34+
-e MONGO_INITDB_ROOT_USERNAME=admin \
35+
-e MONGO_INITDB_ROOT_PASSWORD=supersecret \
36+
--network mongo-network \
37+
--name mongodb \
38+
mongo
39+
```
40+
41+
![docker-mongo](docker-mongo.png)
42+
43+
![mongo-container](mongo-container.png)
44+
45+
4. run mongo-express over mongo-network
46+
47+
```shell
48+
docker run -d \
49+
-p 8081:8081 \
50+
-e ME_CONFIG_MONGODB_ADMINUSERNAME=admin \
51+
-e ME_CONFIG_MONGODB_ADMINPASSWORD=supersecret \
52+
-e ME_CONFIG_MONGODB_SERVER=mongodb \
53+
--network mongo-network \
54+
--name mongo-express \
55+
mongo-express
56+
```
57+
58+
![mongo-express-container](mongo-express-container.png)
59+
60+
docker log for check mongo-express default user/password
61+
62+
![docker-log-for-mongo-express](docker-log-for-mongo-express.png)
63+
64+
![login-web-page](login-web-page.png)
65+
66+
### 3 with docker-compose
67+
68+
1. create docker-compose.yml
69+
70+
```yaml
71+
networks:
72+
mongo-network:
73+
driver: bridge
74+
name: mongo-network
75+
services:
76+
mongodb:
77+
image: mongo:latest
78+
container_name: mongodb
79+
environment:
80+
MONGO_INITDB_ROOT_USERNAME: admin
81+
MONGO_INITDB_ROOT_PASSWORD: supersecret
82+
networks:
83+
- mongo-network
84+
ports:
85+
- 27017:27017
86+
healthcheck:
87+
test: echo 'db.runCommand("ping").ok' | mongosh mongodb://admin:supersecret@localhost:27017/ --quiet
88+
interval: 5s
89+
timeout: 10s
90+
retries: 3
91+
mongo-express:
92+
image: mongo-express:latest
93+
container_name: mongo-express
94+
environment:
95+
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
96+
ME_CONFIG_MONGODB_ADMINPASSWORD: supersecret
97+
ME_CONFIG_MONGODB_SERVER: mongodb
98+
depends_on:
99+
mongodb:
100+
condition: service_healthy
101+
networks:
102+
- mongo-network
103+
ports:
104+
- 8081:8081
105+
```
106+
107+
2. use docker compose command to start
108+
```shell
109+
docker compose up -d
110+
```

architecture.png

204 KB
Loading

docker-compose.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
networks:
2+
mongo-network:
3+
driver: bridge
4+
name: mongo-network
5+
services:
6+
mongodb:
7+
image: mongo:latest
8+
container_name: mongodb
9+
environment:
10+
MONGO_INITDB_ROOT_USERNAME: admin
11+
MONGO_INITDB_ROOT_PASSWORD: supersecret
12+
networks:
13+
- mongo-network
14+
ports:
15+
- 27017:27017
16+
healthcheck:
17+
test: echo 'db.runCommand("ping").ok' | mongosh mongodb://admin:supersecret@localhost:27017/ --quiet
18+
interval: 5s
19+
timeout: 10s
20+
retries: 3
21+
mongo-express:
22+
image: mongo-express:latest
23+
container_name: mongo-express
24+
environment:
25+
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
26+
ME_CONFIG_MONGODB_ADMINPASSWORD: supersecret
27+
ME_CONFIG_MONGODB_SERVER: mongodb
28+
depends_on:
29+
mongodb:
30+
condition: service_healthy
31+
networks:
32+
- mongo-network
33+
ports:
34+
- 8081:8081

docker-log-for-mongo-express.png

22.4 KB
Loading

docker-mongo.png

36.2 KB
Loading

login-web-page.png

94.9 KB
Loading

mongo-container.png

30.5 KB
Loading

mongo-express-container.png

39.4 KB
Loading

network-created.png

23.5 KB
Loading

network-ls.png

32.8 KB
Loading

0 commit comments

Comments
 (0)