How to run golang using docker? - docker

I'm trying to use docker with go lang & PostgreSQL
I have this structure for the project:
-project_name
- src
- app
- config
- main.go
- .env
- docker-compose.yml
- Dockerfile
the docker-compose.yml file contains ( I need GO server & PostgreSQL)
version: '3.9'
services:
app:
container_name: logger_app
build: ..
ports:
- "12000:12000"
restart: on-failure
volumes:
- .:/app
depends_on:
- postgres
networks:
- MYAPP
postgres:
image: postgres:latest
container_name: postgres_db
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
- DATABASE_HOST=${DB_HOST}
ports:
- '5432:5432'
networks:
- MYAPP
networks:
MYAPP:
driver: bridge
The Dockerfile contains:
FROM golang:1.18 as builder
RUN mkdir /app
WORKDIR /app
COPY . .
RUN go get -d -v ./...
RUN go install -v ./...
RUN go build -o /build
EXPOSE 12000
CMD [ "/build" ]
when I run docker-compose up --build I got this error:
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount868285600/Dockerfile: no such file or directory
ERROR: Service 'app' failed to build : Build failed

Change the build line to build: . line. The compose file and Dockerfile are in the same directory.

Related

Docker compose doesnt work i get Error: Cannot find module '#vitejs/plugin-react'

To whom it may concern,
Im trying to run my app with docker compose file and get an error:
This is my docker-compsoe file
version: '3.8'
services:
backend:
container_name: backend
build:
context: .
dockerfile: ./docker/Dockerfile.backend-dev
restart: always
ports:
- '5000:5000'
env_file:
- ./apps/backend/envs/.env.development
volumes:
- type: bind
source: ./apps/backend/src
target: /app/apps/backend/src
- /app/apps/backend/node_modules
frontend:
container_name: frontend
build:
context: .
dockerfile: ./docker/Dockerfile.frontend-dev
restart: always
ports:
- '3000:3000'
volumes:
- type: bind
source: ./apps/frontend/src
target: /app/apps/frontend/src
- /app/apps/frontend/node_modules
And this is my dockerfile of the frontend
FROM node:18.14.0
RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
WORKDIR /app
COPY ./package.json ./pnpm-workspace.yaml ./.npmrc ./
COPY ./apps/frontend/package.json ./apps/frontend/
RUN pnpm i -w
RUN pnpm --filter frontend i
COPY ./tsconfig.base.json ./
COPY ./apps/frontend/ ./apps/frontend/
CMD ["pnpm", "-F", "frontend", "start" ]
And this is the error
apps/frontend start$ vite -c ./vite.config.ts
apps/frontend start: failed to load config from /app/apps/frontend/vite.config.ts
apps/frontend start: error when starting dev server:
apps/frontend start: Error: Cannot find module '#vitejs/plugin-react'
Here is my pnpm workspace.yaml file
packages:
- 'apps/*'
Please help
When running docker-compose up -d

can't up docker-compose on vds ubuntu

My Dockerfile:
FROM node:14-alpine
RUN mkdir /home/app
COPY . /home/app
WORKDIR /home/app
RUN yarn && yarn build
CMD ["yarn", "start:prod"]
My docker-compose.yml:
version: '3.7'
services:
db:
image: postgres:latest
restart: always
env_file:
- .env
volumes:
- $PWD/data/postgres:/var/lib/postgresql/data
networks:
host:
backend:
build: ./
restart: always
depends_on:
- db
networks:
host:
volumes:
db:
I run docker-compose build and got error:
error An unexpected error occurred: "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz: getaddrinfo EAI_AGAIN registry.yarnpkg.com".
if i run docker build --network=host -t back . it work, but i need a docker-compose.
How i can set --network=host for docker-compose?
i tried
network_mode: "host"
but it didn't help

When creating container into docker-compose on a server. Logs show 'exec /usr/local/bin/docker-entrypoint.sh: exec format error'

Using MacBook M1. (Maybe it's a reason of problem)
During uploading my project into server I got this error
$ cat docker-compose.yml
version: '3.8'
services:
db:
image: postgres:13.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env
restart: always
frontend:
image: annarulunat/foodgram_frontend:latest
volumes:
- ../frontend/:/app/result_build/
backend:
image: annarulunat/foodgram:latest
restart: always
volumes:
- static_value:/app/static_backend/
- media_value:/app/media/
depends_on:
- db
env_file:
- ./.env
command: >
sh -c "python manage.py collectstatic --noinput &&
python manage.py migrate &&
gunicorn foodgram.wsgi:application --bind 0:8000"
nginx:
image: nginx:1.21.3-alpine
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ../frontend/build:/usr/share/nginx/html/
- ../docs/:/usr/share/nginx/html/api/docs/
- static_value:/var/html/static_backend/
- media_value:/var/html/media/
restart: always
volumes:
static_value:
media_value:
postgres_data:
$ cat Dockerfile
# build env
FROM node:13.12.0-alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . ./
RUN npm run build
CMD cp -r build result_build
Thank you)))
I tried to add FROM --platform=linux/amd64 <image>-<version> in the Dockerfile and build

docker-compose is giving the error: backend exited with code 2 backend | /bin/sh: syntax error: unterminated quoted string

I am stuck in building the docker containers for MERN stack E-commerce app. These are my following Docker files and Docker compose files. I am getting this error
enter image description here
# Dockerfile for React client
# Build react client
FROM node:lts-buster-slim
# Working directory be app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
COPY package-lock.json /usr/src/app
### Installing dependencies
RUN npm ci
# copy local files to app folder
COPY . /usr/src/app
EXPOSE 3000
CMD ["npm","start"]
# Dockerfile for Node Express Backend
FROM node:lts-buster-slim
# Create App Directory
WORKDIR /usr/src/app
# Install Dependencies
COPY package.json /usr/src/app/package.json
COPY package-lock.json /usr/src/app/package-lock.json
RUN npm ci
COPY . /usr/src/app
# Exports
EXPOSE 5000
CMD ["npm", "run", "dev"]
version: "3.7"
services:
frontend:
build: frontend
ports:
- 3000:3000
stdin_open: true
volumes:
- ./frontend:/usr/src/app
- /usr/src/app/node_modules
container_name: frontend
restart: always
networks:
- react-express
depends_on:
- backend
backend:
container_name: backend
restart: always
build: backend
volumes:
- ./backend:/usr/src/app
- /usr/src/app/node_modules
depends_on:
- mongo
networks:
- express-mongo
- react-express
ports:
- 5000:5000
mongo:
container_name: mongo
restart: always
image: mongo:4.2.0
volumes:
- ./data:/data/db
networks:
- express-mongo
ports:
- 27017:27017
networks:
react-express:
express-mongo:
I am getting this error when I execute the command: "docker-compose up". I am doing a MERN E-Commerce App. The error is: backend | /bin/sh: syntax error: unterminated quoted string
backend exited with code 2

Docker Error: Cannot cerate container for service <container name>: status code not OK but 500

I used docker-compose to create docker containers in my React, Node.js, and Postgres structured project.
After I created Dockerfile and docker-compose.yml, I did docker up 'docker-compose up --build.'
Then, I wasn't be able to create containers, and get an errors.
I get Error says:
Error 1
Error 2
Error 3
How can I fix it and successfully build containers?
Here is a docker-compose.yml file in './'
version: '3'
services:
server:
container_name: mylivingcity_server
build: ./server
expose:
- 3001
ports:
- 3001:3001
volumes:
- ./server/config:/usr/src/app/server/config
- ./server/controllers:/usr/src/app/server/controllers
- ./server/db:/usr/src/app/server/db
command: npm run start
postgres:
image: postgres:12
container_name: mylivingcity_postgres
ports:
- 5432:5432
volumes:
- ./postgres/data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=mylivingcity
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
frontend:
container_name: mylivingcity_frontend
build: ./frontend
expose:
- 3000
ports:
- 3000:3000
volumes:
- ./frontend/src:/usr/src/app/frontend/src
- ./frontend/public:/usr/src/app/frontend/public
command: npm start
stdin_open: true
Here is a Dockerfile in './frontend'
FROM node:12
# Create frontend directory
RUN mkdir -p /usr/src/app/frontend/
WORKDIR /usr/src/app/frontend/
# Install dependencies
COPY package*.json /usr/src/app/frontend/
RUN npm install
COPY . /usr/src/app/frontend/
CMD [ "npm" , "start" ]
Here is a Dockerfile in './server'
FROM node:12
# Create server directory
RUN mkdir -p /usr/src/app/server/
WORKDIR /usr/src/app/server/
# Install dependencies
COPY package*.json /usr/src/app/server/
RUN npm install
COPY . /usr/src/app/server/
CMD [ "npm" , "run" , "start" ]

Resources