Every time, I run “docker-compose up” I get this error
//Error
> $ docker-compose up --build
Creating network "bucket-api_fullstack" with driver "bridge"
Building bucket
Step 1/17 : FROM golang:1.15-alpine as builder
---> 3dae2ccc15b8
Step 2/17 : RUN mkdir /app
---> Using cache
---> 70dd1c583533
Step 3/17 : ADD . /app
---> Using cache
---> 4586c50cca46
Step 4/17 : WORKDIR /app
---> Using cache
---> c3a943c24b9e
Step 5/17 : RUN go clean --modcache
---> Using cache
---> 200b57f5142e
Step 6/17 : RUN go mod download
---> Using cache
---> 25e6672cddbe
Step 7/17 : RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./src/
---> Using cache
---> 625a83d39c9d
Step 8/17 : FROM alpine:latest
---> e50c909a8df2
Step 9/17 : RUN apk --no-cache add ca-certificates
---> Using cache
---> 9fb84fe65803
Step 10/17 : RUN apk add --no-cache git make musl-dev go
---> Using cache
---> 81520138b2d7
Step 11/17 : COPY --from=builder /app/main .
---> Using cache
---> c285894862aa
Step 12/17 : ENV GOROOT /usr/lib/go
---> Using cache
---> c5a2790f18cb
Step 13/17 : ENV GOPATH /go
---> Using cache
---> 8fdf6d244cd1
Step 14/17 : ENV PATH /go/bin:$PATH
---> Using cache
---> a40c53d193c1
Step 15/17 : RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin
---> Using cache
---> b199ed72e3f5
Step 16/17 : EXPOSE 8084
---> Using cache
---> 4ab9ad5a24af
Step 17/17 : CMD ["./main"]
---> Using cache
---> 4f1478c4b83f
Successfully built 4f1478c4b83f
Successfully tagged bucketapi:latest
Creating bucket-database ... done
Creating bucket-api ... done
Attaching to bucket-database, bucket-api
bucket-api | rbucket pagal!123 bucket-database 3305 rb_db
bucket-api | panic: dial tcp 192.168.160.2:3305: connect: connection refused
bucket-api |
bucket-api | goroutine 1 [running]:
bucket-api |
bucket-api | /app/src/datasources/mysql/bucket_db/bucket_db.go:51 +0x554
bucket-database | 2021-02-12 11:50:17+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
bucket-database | 2021-02-12 11:50:17+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
bucket-database | 2021-02-12 11:50:17+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
bucket-database | 2021-02-12T11:50:18.393432Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.23) starting as process 1
bucket-database | 2021-02-12T11:50:18.941771Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
bucket-database | 2021-02-12T11:50:23.269865Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
bucket-database | 2021-02-12T11:50:23.974635Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
bucket-database | 2021-02-12T11:50:24.336745Z 0 [System] [MY-010229] [Server] Starting XA crash recovery...
bucket-database | 2021-02-12T11:50:24.357326Z 0 [System] [MY-010232] [Server] XA crash recovery finished.
bucket-database | 2021-02-12T11:50:25.059647Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
bucket-database | 2021-02-12T11:50:25.060266Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
bucket-database | 2021-02-12T11:50:25.191338Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
bucket-database | 2021-02-12T11:50:25.327133Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.23' socket: '/var/run/mysqld/mysqld.sock'
port: 3306 MySQL Community Server - GPL.
bucket-api exited with code 2
THIS MY DOCKER-COMPOSE FILE
> version: '3.8'
>
> services:
> # MYSQL DATABASE DOCKER
> bucket-mysql:
> image: mysql:latest
> container_name: bucket-database
> command: --default-authentication-plugin=mysql_native_password
> ports:
> - "127.0.0.1:3305:3306"
> environment:
> MYSQL_ROOT_PASSWORD: "pagal!123"
> MYSQL_USER: "rbucket"
> MYSQL_PASSWORD: "root"
> MYSQL_DATABASE: "rb_db"
> networks:
> - fullstack
> volumes:
> - database_mysql:/var/lib/mysql
> restart: always
> cap_add:
> - SYS_NICE
> healthcheck:
> test: ["CMD-SHELL", "echo 'select 1' |mysql -u root -p'pagal!123' --silent"]
> interval: 30s
> timeout: 20s
> retries: 6
>
> #API DOCKER
> bucket:
> image: bucketapi
> build: .
> container_name: bucket-api
> environment:
> MYSQL_ROOT_PASSWORD: "pagal!123"
> MYSQL_USER: "rbucket"
> MYSQL_PASSWORD: "pagal!123"
> MYSQL_DATABASE: "rb_db"
> MYSQL_HOST: "bucket-database"
> MYSQL_PORT: "3305"
> ports:
> - "8084:8084"
> # restart: on-failure
> # volumes:
> # - ./src:/usr/src/app/
> depends_on:
> - bucket-mysql
> networks:
> - fullstack
>
>
> volumes:
> database_mysql:
>
> networks:
> fullstack:
> driver: bridge
THIS IS MY DOCKER FILE
> #Builder image build the go binary : Setting the alias as builder
>
> FROM golang:1.15-alpine as builder
>
> RUN mkdir /app
>
> # add this file directory to the image
>
> ADD . /app
>
> # directory where the source file execution takes place
>
> WORKDIR /app
>
> # RUN some go commands
>
> RUN go clean --modcache
>
> RUN go mod download
>
> RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./src/
>
> # Our production image used to run our app
>
> FROM alpine:latest
>
> RUN apk --no-cache add ca-certificates
>
> RUN apk add --no-cache git make musl-dev go
>
> COPY --from=builder /app/main .
>
> # Configure GO
>
> ENV GOROOT /usr/lib/go
>
> ENV GOPATH /go
>
> ENV PATH /go/bin:$PATH
>
> RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin
>
> EXPOSE 8084
>
> CMD ["./main"]
IAM GETTING THE ERROR FROM THIS FILE
> //client info
>
> var (
>
> client *sql.DB
>
> )
>
> func init() {
>
> // loaDerr := godotenv.Load()
>
> // if loaDerr != nil {
>
> // log.Fatal("Error loading .env file")
>
> // }
>
> username := os.Getenv("MYSQL_USER")
>
> password := os.Getenv("MYSQL_ROOT_PASSWORD")
>
> host := os.Getenv("MYSQL_HOST")
>
> port := os.Getenv("MYSQL_PORT")
>
> schema := os.Getenv("MYSQL_DATABASE")
>
> fmt.Println(username, password, host, port, schema)
>
> dataSourceName := fmt.Sprintf(
>
> "%s:%s@tcp(%s:%s)/%s?charset=utf8",
>
> username,
>
> password,
>
> host,
>
> port,
>
> schema,
>
> )
>
> var err error
>
> //connect to the database server
>
> client, err = sql.Open("mysql", dataSourceName)
>
> if err != nil {
>
> panic(err)
>
> }
>
> //checking the connection
>
> if connectionErr := client.Ping(); connectionErr != nil {
>
> panic(connectionErr)
>
> }
>
> fmt.Println("Database connection is been established succesfully")
>
> }
>
> //GetClient : this method returns the connected client database
>
> func GetClient() *sql.DB {
>
> return client
>
> }