Skip to content

Commit eb6c187

Browse files
committed
Update the Dockerfile, docker-compose and .env files
1 parent 23f5382 commit eb6c187

File tree

3 files changed

+67
-67
lines changed

3 files changed

+67
-67
lines changed

.env

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
# Postgres Live
2-
DB_HOST=fullstack-postgres # used when running the app with docker
2+
DB_HOST=fullstack-postgres
33
# DB_HOST=127.0.0.1 # when running the app without docker
44
DB_DRIVER=postgres
55
API_SECRET=98hbun98h # Used for creating a JWT. Can be anything
66
DB_USER=steven
7-
DB_PASSWORD=
7+
DB_PASSWORD=password
88
DB_NAME=fullstack_api
99
DB_PORT=5432
1010

11+
# Used by pgadmin service
1112
PGADMIN_DEFAULT_EMAIL=live@admin.com
1213
PGADMIN_DEFAULT_PASSWORD=password
1314

1415
# Postgres Test
15-
TEST_DB_HOST=postgres_test # used when running the app with docker
16+
TEST_DB_HOST=postgres_test
1617
# TEST_DB_HOST=127.0.0.1 # when running the app without docker
1718
TEST_DB_DRIVER=postgres
1819
TEST_API_SECRET=98hbun98h
1920
TEST_DB_USER=steven
20-
TEST_DB_PASSWORD=
21+
TEST_DB_PASSWORD=password
2122
TEST_DB_NAME=fullstack_api_test
2223
TEST_DB_PORT=5432
2324

2425

2526
# # Mysql Live
26-
# DB_HOST=fullstack-mysql # used when running the app with docker
27+
# DB_HOST=fullstack-mysql
2728
# # DB_HOST=127.0.0.1 # when running the app without docker
2829
# DB_DRIVER=mysql
2930
# API_SECRET=98hbun98h # Used for creating a JWT. Can be anything
@@ -34,7 +35,7 @@ TEST_DB_PORT=5432
3435

3536

3637
# # Mysql Test
37-
# TEST_DB_HOST=mysql_test # used when running the app with docker
38+
# TEST_DB_HOST=mysql_test
3839
# # TEST_DB_HOST=127.0.0.1 # when running the app without docker
3940
# TEST_DB_DRIVER=mysql
4041
# TEST_API_SECRET=98hbun98h

Dockerfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ WORKDIR /app
1616
# Copy go mod and sum files
1717
COPY go.mod go.sum ./
1818

19-
# RUN go mod tidy
20-
2119
# Download all dependencies. Dependencies will be cached if the go.mod and the go.sum files are not changed
2220
RUN go mod download
2321

2422
# Copy the source from the current directory to the working Directory inside the container
2523
COPY . .
24+
2625
# Build the Go app
2726
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
2827

@@ -32,7 +31,7 @@ RUN apk --no-cache add ca-certificates
3231

3332
WORKDIR /root/
3433

35-
# Copy the Pre-built binary file from the previous stage
34+
# Copy the Pre-built binary file from the previous stage. Observe we also copied the .env file
3635
COPY --from=builder /app/main .
3736
COPY --from=builder /app/.env .
3837

docker-compose.yml

+58-58
Original file line numberDiff line numberDiff line change
@@ -9,79 +9,79 @@ services:
99
volumes:
1010
- api:/usr/src/app/
1111
depends_on:
12-
- fullstack-postgres # Uncomment this when using postgres.
13-
# - fullstack-mysql # Uncomment this when using mysql.
12+
# - fullstack-postgres # Uncomment this when using postgres.
13+
- fullstack-mysql # Uncomment this when using mysql.
1414
networks:
1515
- fullstack
1616

1717

18-
fullstack-postgres:
19-
image: postgres:latest
20-
container_name: full_db_postgres
21-
environment:
22-
- POSTGRES_USER=${DB_USER}
23-
- POSTGRES_PASSWORD=${DB_PASSWORD}
24-
- POSTGRES_DB=${DB_NAME}
25-
- DATABASE_HOST=${DB_HOST}
26-
ports:
27-
- '5432:5432'
28-
volumes:
29-
- database_postgres:/var/lib/postgresql/data
30-
networks:
31-
- fullstack
32-
33-
pgadmin:
34-
image: dpage/pgadmin4
35-
container_name: pgadmin_container
36-
environment:
37-
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
38-
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
39-
depends_on:
40-
- fullstack-postgres
41-
ports:
42-
- "5050:80"
43-
networks:
44-
- fullstack
45-
restart: unless-stopped
46-
47-
48-
# fullstack-mysql:
49-
# image: mysql:5.7
50-
# container_name: full_db_mysql
51-
# ports:
52-
# - 3306:3306
53-
# environment:
54-
# - MYSQL_ROOT_HOST=${DB_HOST}
55-
# - MYSQL_USER=${DB_USER}
56-
# - MYSQL_PASSWORD=${DB_PASSWORD}
57-
# - MYSQL_DATABASE=${DB_NAME}
58-
# - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
18+
# fullstack-postgres:
19+
# image: postgres:latest
20+
# container_name: full_db_postgres
21+
# environment:
22+
# - POSTGRES_USER=${DB_USER}
23+
# - POSTGRES_PASSWORD=${DB_PASSWORD}
24+
# - POSTGRES_DB=${DB_NAME}
25+
# - DATABASE_HOST=${DB_HOST}
26+
# ports:
27+
# - '5432:5432'
5928
# volumes:
60-
# - database_mysql:/var/lib/mysql
29+
# - database_postgres:/var/lib/postgresql/data
6130
# networks:
6231
# - fullstack
63-
64-
# phpmyadmin:
65-
# image: phpmyadmin/phpmyadmin
66-
# container_name: phpmyadmin_container
67-
# depends_on:
68-
# - fullstack-mysql
32+
33+
# pgadmin:
34+
# image: dpage/pgadmin4
35+
# container_name: pgadmin_container
6936
# environment:
70-
# - PMA_HOST=mysql # Note the "mysql". Must be the name of the what you used as the mysql service.
71-
# - PMA_USER=${DB_USER}
72-
# - PMA_PORT=${DB_PORT}
73-
# - PMA_PASSWORD=${DB_PASSWORD}
37+
# PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
38+
# PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
39+
# depends_on:
40+
# - fullstack-postgres
7441
# ports:
75-
# - 9090:80
76-
# restart: always
42+
# - "5050:80"
7743
# networks:
7844
# - fullstack
45+
# restart: unless-stopped
46+
47+
48+
fullstack-mysql:
49+
image: mysql:5.7
50+
container_name: full_db_mysql
51+
ports:
52+
- 3306:3306
53+
environment:
54+
- MYSQL_ROOT_HOST=${DB_HOST}
55+
- MYSQL_USER=${DB_USER}
56+
- MYSQL_PASSWORD=${DB_PASSWORD}
57+
- MYSQL_DATABASE=${DB_NAME}
58+
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
59+
volumes:
60+
- database_mysql:/var/lib/mysql
61+
networks:
62+
- fullstack
63+
64+
phpmyadmin:
65+
image: phpmyadmin/phpmyadmin
66+
container_name: phpmyadmin_container
67+
depends_on:
68+
- fullstack-mysql
69+
environment:
70+
- PMA_HOST=fullstack-mysql # Note the "mysql". Must be the name of the what you used as the mysql service.
71+
- PMA_USER=${DB_USER}
72+
- PMA_PORT=${DB_PORT}
73+
- PMA_PASSWORD=${DB_PASSWORD}
74+
ports:
75+
- 9090:80
76+
restart: always
77+
networks:
78+
- fullstack
7979

8080

8181
volumes:
8282
api:
83-
database_postgres: # Uncomment this when using postgres.
84-
# database_mysql: # Uncomment this when using mysql.
83+
# database_postgres: # Uncomment this when using postgres.
84+
database_mysql: # Uncomment this when using mysql.
8585

8686
# Networks to be created to facilitate communication between containers
8787
networks:

0 commit comments

Comments
 (0)