Skip to content

Instantly share code, notes, and snippets.

@num8er
Last active May 19, 2025 08:42
Show Gist options
  • Save num8er/1adc561b50f5732b515d84a8e55d4af2 to your computer and use it in GitHub Desktop.
Save num8er/1adc561b50f5732b515d84a8e55d4af2 to your computer and use it in GitHub Desktop.
Dockerized environment for local development in Go
services:
smls-api:
build:
context: .
dockerfile: Dockerfile.local
container_name: smls-api
volumes:
- .:/app
- go-modules:/go/pkg/mod
ports:
- "3080:3080"
- "3045:3045" # Delve debugging port
environment:
- MYSQL_HOST=smls-db
- MYSQL_PORT=3306
- REDIS_HOST=smls-redis
- REDIS_PORT=6379
depends_on:
- smls-db
- smls-redis
networks:
- smls-network
tty: true
stdin_open: true
command: /bin/zsh
smls-db:
image: mysql:8.0
container_name: smls-db
restart: always
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=smals
- MYSQL_USER=smals
- MYSQL_PASSWORD=smals
- MYSQL_DATABASE=smals
volumes:
- ./.data/mysql:/var/lib/mysql
networks:
- smls-network
command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
smls-redis:
image: redis:7.0-alpine
container_name: smls-redis
restart: always
ports:
- "6379:6379"
volumes:
- ./.data/redis:/data
networks:
- smls-network
command: redis-server --appendonly yes
networks:
smls-network:
driver: bridge
volumes:
go-modules:
driver: local
FROM golang:1.24
WORKDIR /app
# Install required system dependencies
RUN apt-get update && apt-get install -y \
wget \
git \
curl \
zsh \
fonts-powerline \
locales \
&& rm -rf /var/lib/apt/lists/*
# Set up locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# Install Oh My Zsh
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
# Install popular Oh My Zsh plugins
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
RUN git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# Configure zsh with plugins
RUN sed -i 's/plugins=(git)/plugins=(git golang docker docker-compose zsh-syntax-highlighting zsh-autosuggestions)/' ~/.zshrc
# Install development and debugging tools
RUN go install github.com/air-verse/air@latest \
&& go install github.com/swaggo/swag/cmd/swag@latest \
&& go install github.com/go-delve/delve/cmd/dlv@latest
# Expose Delve debugging port
EXPOSE 3045
# Add useful aliases for the project including debugging
RUN echo '\n\
# SMLS Backend aliases\n\
alias build-api="make build-api"\n\
alias build-docs="make build-api-docs"\n\
alias run-local="air -- --env local"\n\
alias run-dev="air -- --env dev"\n\
alias run-demo="./bin/smls-api --env demo"\n\
alias run-prod="./bin/smls-api --env prod"\n\
\n\
# Debugging aliases\n\
alias debug-local="dlv debug cmd/api/main.go -- --env local"\n\
alias debug-dev="dlv debug cmd/api/main.go -- --env dev"\n\
alias debug-headless="dlv debug --headless --listen=:3045 --api-version=2 --accept-multiclient cmd/api/main.go --"\n\
alias debug-local-headless="dlv debug --headless --listen=:3045 --api-version=2 --accept-multiclient cmd/api/main.go -- --env local"\n\
' >> ~/.zshrc
# Set the working directory permissions
RUN mkdir -p /app
WORKDIR /app
# Set ZSH as the default shell
SHELL ["/bin/zsh", "-c"]
CMD ["/bin/zsh"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment