Category : go

I am trying to connect to docker postgres database from the golang code. Command used to create the postgres container: docker run -d -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password –name my-postgres -p 5432:5432 postgres To create the database I run: PS C:UsersAylinDesktopfarmers> docker exec -it my-postgres bash [email protected]:/# psql -U postgres psql (13.2 (Debian 13.2-1.pgdg100+1)) Type "help" ..

Read more

I have the following dockerfile: FROM golang:1.16.3 as compile WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . # CGO_ENABLED for static linking library RUN go env -w GOPRIVATE="github.com/<some_account>/*"; GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.version=$1 -X main.build=`date -u +%Y%m%d.%H%M%S`" -o /app/server server.go FROM scratch #WORKDIR / #FROM alpine:latest #RUN ..

Read more

I have a server code written in golang that listen to http and connecting to mongodb at localhost:27017 at my development machine and on aws ec-2 instance also the same host. All is working well when I run it via go run main.go. sudo docker build -t server /mnt/c/code/tttfm/backend/server returns => [internal] load build definition ..

Read more

command-line-arguments ./anotherruncontainer.go:38:4: cannot use portBinding (type "github.com/docker/go-connections/nat".PortMap) as type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortMap in field value Here is my code : package main import ( "context" "fmt" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/docker/go-connections/nat" ) func main (){ CreateNewContainer("mar82022") } func CreateNewContainer(image string) (string, error) { cli, err := client.NewEnvClient() if err != nil { fmt.Println("Unable to create docker ..

Read more

command-line-arguments ./anotherruncontainer.go:38:4: cannot use portBinding (type "github.com/docker/go-connections/nat".PortMap) as type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortMap in field value Here is my code : package main import ( "context" "fmt" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/docker/go-connections/nat" ) func main (){ CreateNewContainer("mar82022") } func CreateNewContainer(image string) (string, error) { cli, err := client.NewEnvClient() if err != nil { fmt.Println("Unable to create docker ..

Read more

I figured some strange behaviour of my program when I run it inside a Docker container: My golang code: package main import ( "fmt" "os" "path/filepath" ) func main() { fmt.Println(os.Args[0]) fmt.Println(filepath.Abs("./")) fmt.Println(os.Executable()) } My Dockerfile: FROM golang:latest as build WORKDIR /go/src/test/ COPY . . RUN go build . FROM scratch COPY –from=build /go/src/test/test /app/test ..

Read more

Good day everyone. I’m in the middle of a task using our docker image to build go microservice. To reduce build time, keep the images under control. I expect that after downloading the golang image from the docker hub, upload it to our registry and use it in all the dockerfiles of our microservices. As ..

Read more