Deployment > Docker
GoLang simple example:
FROM golang:1.20.1-alpine3.17
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY *.go ./
RUN go build -o /gs-ping
EXPOSE 3000
CMD [ "/gs-ping" ]
The following command for creating image:
docker build -t gs-ping .
Common commands:
Run docker image right from registry:
docker run -d --name nginx-base -p 80:80 nginx:alpine
How to copy something from the running container:
docker cp nginx-base:/etc/nginx/conf.d/default.conf C:\temp\default.conf
How to create and publish containers
First we have to create it:
docker build . -t docker.io/dontomato/serviceexp:gs-ping
If you need specific architecture:
docker build . -t docker.io/dontomato/serviceexp:gs-ping --platform linux/aarch64
Then login docker login -u dontomato
. Then push:
docker push docker.io/dontomato/serviceexp:gs-ping
Then use it in docker compose:
services:
api1:
image: dontomato/serviceexp:gs-ping
environment:
- ID=1
- PORT=3001
- GIN_MODE=release
api2:
image: dontomato/serviceexp:gs-ping
environment:
- ID=2
- PORT=3002
- GIN_MODE=release
reverseproxy:
image: dontomato/serviceexp:gs-rp
ports:
- "80:80"
depends_on:
- api1
- api2
To use docker on server side
Solve problem with permissions (step by step):
sudo groupadd docker
sudo usermod -aG docker ${USER}
Then you need to logout and login again. Then to check that docker works:
docker run hello-world
To login inside of docker container:
docker exec -it apps_reverse-proxy_1 /bin/sh --login
Docker compose
Main commands:
docker-compose up
docker-compose down