This is my Dockerfile
# Start by selecting the base image for our service
FROM golang:alpine
# Specifying app as our work directory in which
# futher instructions should run into
WORKDIR /go/src/github.com/urlshortener
# Copy everything from project into filesystem of container
COPY . .
# Download all neededed project dependencies
RUN go mod download
# Build the project executable binary
RUN go build -o main .
# Run/Starts the app executable binary
CMD ["./main"]
This is my directory structure
go.mod
go.sum
Dockerfile
README.md
docker-compose.yml
redis.conf
handlers
|_ handlers.go
shortener
|_ shorteners.go
|_ shorteners_test.go
storage
|_ storage_service.go
|_ storage_service_test.go
I have this in my docker-compose.yml:
version: "3.8"
services:
redis:
container_name: "redis"
image: redis:alpine
# Specify the redis.conf file to use and add a password.
command: redis-server /usr/local/etc/redis/redis.conf --requirepass mypassword
ports:
- "6379:6379"
# map the volumes to that redis has the custom conf file from this project.
volumes:
- $PWD/redis.conf:/usr/local/etc/redis/redis.conf
go:
container_name: "redisapi"
build:
# build the image using the Dockerfile we have in this project. Can use an image instead.
context: .
ports:
- "8080:8080"
When I run docker-compose up -d and then docker-compose ps
I can see one of the containers is in exit 2 state
urlshortener git:(main) ✗ docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------
redis docker-entrypoint.sh redis ... Up 0.0.0.0:6379->6379/tcp
redisapi ./main Exit 2
Any advice/tips for debugging would be appreciated.