Docker varnish error 503 backend fetch failed - docker

Here is default.vcl
vcl 4.1;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
My docker-composer.yml
version: "3"
services:
varnish:
image: varnish:stable
container_name: varnish
volumes:
- "./default.vcl:/etc/varnish/default.vcl"
ports:
- "80:80"
tmpfs:
- /var/lib/varnish:exec
environment:
- VARNISH_SIZE=2G
depends_on:
- "node"
node:
build: ./
container_name: node
ports:
- "8080:8000"
My Dockerfile
FROM node:10-alpine
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY package*.json ./
USER node
RUN npm install
COPY --chown=node:node . .
EXPOSE 8080
CMD [ "node", "app.js" ]
When I run the application through http://localhost:8080/ it works and when I run it directly in port 80 like this http://localhost/ it throws
Error 503 Backend fetch failed
Am I missing out something in configuring port? Or How can I check the varnish log through docker?

Related

AdonisJS 5 Dockerfile - Cannot find ace

I have a docker setup with AdonisJS 5. I'm currently trying to get it started (and it builds just fine). But as discussed a bit further down, the ace command cannot be found. ace is the CLI package for AdonisJS (think ng for Angular)
This is my Dockerfile:
ARG NODE_IMAGE=node:16.13.1-alpine
FROM $NODE_IMAGE AS base
RUN apk --no-cache add dumb-init
RUN mkdir -p /home/node/app && chown node:node /home/node/app
WORKDIR /home/node/app
USER node
RUN mkdir tmp
FROM base AS dependencies
COPY --chown=node:node ./package*.json ./
RUN npm ci
RUN npm i #adonisjs/cli
COPY --chown=node:node . .
FROM dependencies AS build
RUN node ace build --production
FROM base AS production
ENV NODE_ENV=production
ENV PORT=$PORT
ENV HOST=0.0.0.0
COPY --chown=node:node ./package*.json ./
RUN npm ci --production
COPY --chown=node:node --from=build /home/node/app/build .
EXPOSE $PORT
CMD [ "dumb-init", "node", "service/build/server.js" ]
And this is my docker-compose.yml:
version: '3.9'
services:
postgres:
container_name: postgres
image: postgres
restart: always
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
- POSTGRES_USER=${POSTGRES_USER:-user}
networks:
- family-service-network
volumes:
- fn-db_volume:/var/lib/postgresql/data
adminer:
container_name: adminer
image: adminer
restart: always
networks:
- family-service-network
ports:
- 8080:8080
minio:
container_name: storage
image: 'bitnami/minio:latest'
ports:
- '9000:9000'
- '9001:9001'
environment:
- MINIO_ROOT_USER=user
- MINIO_ROOT_PASSWORD=password
- MINIO_SERVER_ACCESS_KEY=access-key
- MINIO_SERVER_SECRET_KEY=secret-key
networks:
- family-service-network
volumes:
- fn-s3_volume:/var/lib/postgresql/data
fn_service:
container_name: fn_service
restart: always
build:
context: ./service
target: dependencies
ports:
- ${PORT:-3333}:${PORT:-3333}
- 9229:9229
networks:
- family-service-network
env_file:
- ./service/.env
volumes:
- ./:/home/node/app
- /home/node/app/node_modules
depends_on:
- postgres
command: dumb-init node ace serve --watch --node-args="--inspect=0.0.0.0"
volumes:
fn-db_volume:
fn-s3_volume:
networks:
family-service-network:
When I run this with docker-compose up everything works, except for the fn_service.
I get the error:
Error: Cannot find module '/home/node/app/ace'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
node:internal/modules/cjs/loader:936
throw err;
^
I followed this tutorial, and I can't seem to find anything by googling. I'm sure it's something miniscule.
Any help would be appreciated.

Cant Reach Docker Container

I am trying to build my microservice project with docker. I can reach vue app but i cant reach my identity service. I tried some small projects with the same dockerfile and compose file it worked. Netstat gives same url i checked that. I tried nearly everthing i see but cant find any solution.
Dockercompose
version: "3.8"
services:
category:
container_name: category
build:
context: .
dockerfile: sln/CodeChat-Backend/Category/Dockerfile
ports:
- "7000:7000"
depends_on:
- redis
networks:
- es-network
gateway:
container_name: gateway
build:
context: .
dockerfile: sln/CodeChat-Backend/Gateway/Dockerfile
ports:
- "7007:7007"
depends_on:
- identity
- category
- message
networks:
- es-network
identity:
container_name: identity
restart: always
build:
context: .
dockerfile: sln/CodeChat-Backend/Identity/Dockerfile
ports:
- "7001:7001"
depends_on:
- mssql
networks:
- es-network
message:
container_name: message
build:
context: .
dockerfile: sln/CodeChat-Backend/Message/Dockerfile
ports:
- "7002:7002"
depends_on:
- elasticsearch
- rabbitmq
- redis
networks:
- es-network
codechat-web:
container_name: vue
build:
context: .
dockerfile: /Dockerfile
environment:
- CHOKIDAR_USEPOLLING=true
ports:
- "8081:8080"
networks:
- es-network
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.0.0
container_name: elasticsearch
restart: always
environment:
- cluster.name=docker-cluster
- xpack.security.enabled=false
- discovery.type=single-node
ulimits:
memlock:
soft: -1
hard: -1
ports:
- "9200:9200"
networks:
- es-network
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: "rabbitmq"
ports:
- "5672:5672"
- "15672:15672"
networks:
- es-network
redis:
image: redis
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- "6379:6379"
networks:
- es-network
mssql:
image: mcr.microsoft.com/mssql/server:2019-latest
environment:
SA_PASSWORD: "1576Orhan_"
ACCEPT_EULA: "Y"
ports:
- "1433:1433"
networks:
- es-network
networks:
es-network:
driver: bridge
Vue dockerfile
FROM node:lts-alpine
RUN npm install -g http-server
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 80
CMD [ "http-server", "dist" ]
Category Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app
EXPOSE 80
COPY sln/CodeChat-Backend/Category/*.csproj sln/CodeChat-Backend/Category/
COPY sln/CodeChat-Backend/Core/*.csproj sln/CodeChat-Backend/Core/
RUN dotnet restore sln/CodeChat-Backend/Category/*.csproj
COPY . .
RUN dotnet publish sln/CodeChat-Backend/Category/*.csproj -c Release -o out
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS runtime
WORKDIR /app
COPY --from=build /app/out .
ENV ASPNETCORE_URLS http://*:7000
ENV ASPNETCORE_ENVIRONMENT docker
EXPOSE 7000
ENTRYPOINT ["dotnet","Category.dll"]
Gateway dockerfile
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app
EXPOSE 80
COPY sln/CodeChat-Backend/Gateway/*.csproj sln/CodeChat-Backend/Gateway/
RUN dotnet restore sln/CodeChat-Backend/Gateway/*.csproj
COPY . .
RUN dotnet publish sln/CodeChat-Backend/Gateway/*.csproj -c Release -o out
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS runtime
WORKDIR /app
COPY --from=build /app/out .
ENV ASPNETCORE_URLS http://*:7007
ENV ASPNETCORE_ENVIRONMENT docker
EXPOSE 7007
ENTRYPOINT ["dotnet","Gateway.dll"]
Identity dockerfile
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /app
EXPOSE 80
COPY sln/CodeChat-Backend/Identity/*.csproj sln/CodeChat-Backend/Identity/
COPY sln/CodeChat-Backend/Core/*.csproj sln/CodeChat-Backend/Core/
RUN dotnet restore sln/CodeChat-Backend/Identity/*.csproj
COPY . .
RUN dotnet publish sln/CodeChat-Backend/Identity/*.csproj -c Release -o out
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS runtime
WORKDIR /app
COPY --from=build /app/out .
ENV ASPNETCORE_URLS http://*:7001
ENV ASPNETCORE_ENVIRONMENT docker
EXPOSE 7001
ENTRYPOINT ["dotnet","Identity.dll"]
Message dockerfile
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app
EXPOSE 80
COPY sln/CodeChat-Backend/Message/*.csproj sln/CodeChat-Backend/Message/
COPY sln/CodeChat-Backend/Core/*.csproj sln/CodeChat-Backend/Core/
RUN dotnet restore sln/CodeChat-Backend/Message/*.csproj
COPY . .
RUN dotnet publish sln/CodeChat-Backend/Message/*.csproj -c Release -o out
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS runtime
WORKDIR /app
COPY --from=build /app/out .
ENV ASPNETCORE_URLS http://*:7002
ENV ASPNETCORE_ENVIRONMENT docker
EXPOSE 7002
ENTRYPOINT ["dotnet","Message.dll"]
Gateway ocelot
{
"Routes": [
{
"DownstreamPathTemplate": "/api/category/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7000
}
],
"UpstreamPathTemplate": "/category/{everything}",
"UpstreamHttpMethod": [ "GET","POST","PUT","DELETE" ]
},
{
"DownstreamPathTemplate": "/api/user/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7001
}
],
"UpstreamPathTemplate": "/user/{everything}",
"UpstreamHttpMethod": [ "GET","POST","PUT","DELETE" ]
},
{
"DownstreamPathTemplate": "/api/message/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7002
}
],
"UpstreamPathTemplate": "/message/{everything}",
"UpstreamHttpMethod": [ "GET","POST","PUT","DELETE" ]
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:7007"
}
}

flask_1 | WebDriverException: Message: 'chromedriver' executable needs to be in PATH

Steps I followed build using docker-compose
I setup python robot framework with flask based application
I created Dockerfile
DockerFile
FROM alpine:latest
COPY . /app
WORKDIR /app
RUN ls -la /
RUN apk add --no-cache sqlite py3-pip
RUN pip3 install -r requirements.txt
ENV FLASK_PORT 8181
ENV FLASK_APP demo_app
CMD ["sh", "run.sh"]
COPY testing/ui/config/ /app/tests/config/
COPY testing/ui/pages/ /app/tests/pages/
COPY testing/ui/steps/ /app/tests/steps/
COPY testing/ui/test_data/ /app/tests/test_data/
COPY testing/ui/tests/ /app/tests/tests/
COPY testing/ui/test_suites/ /app/tests/test_suites/
RUN ls -la /
WORKDIR /app/tests/test_suites/
CMD ["sh","run_ui_negative_tests.sh"]
I created docker-compose file
version: '3'
services:
flask:
hostname: demoapp
image: demoapp:0.0.1
build:
context: .
dockerfile: ./Dockerfile
links:
- chrome
tty: true
chrome:
image: selenium/node-chrome:4.0.0-alpha-7-prerelease-20201009
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
ports:
- "5900:5900"
selenium-hub:
image: selenium/hub:4.0.0-alpha-7-prerelease-20201009
container_name: selenium-hub
ports:
- "4442:4442"
Error I got
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
h
Try to add path where your chrome driver application is stored.
driver = webdriver.Chrome(executable_path=r'your_path\chromedriver.exe')

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" ]

How to include volumes in my docker configuration?

I have a docker-compose configuration for an MEAN app that's working fine.
I would like my angular (ng serve) and express servers (nodemon) to rerun automaticaly when I hit ctrl + s as if I was running my app in local.
For that, my containers need to be aware that the files changed.
How can I do that ?
Angular's Dockerfile :
FROM node:10
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . ./
EXPOSE 4200
CMD ["npm", "start"]
Express's Dockerfile :
FROM node:6
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . ./
EXPOSE 3000
CMD ["npm", "start"]
docker-compose.yml :
version: '3'
services:
angular: # name of the first service
build: client # specify the directory of the Dockerfile
ports:
- "4200:4200"
express: #name of the second service
build: server # specify the directory of the Dockerfile
ports:
- "3000:3000"
links:
- database
database: # name of the third service
image: mongo
ports:
- "27017:27017"
Both Angular and Express have an .dockerignore for node_modules
If you are in dev environment, you can add the volumes section in your docker-compose.yml as below :
services:
angular: # name of the first service
build: client # specify the directory of the Dockerfile
ports:
- "4200:4200"
volumes:
- /path/in/host/machine:/path/in/container
express: #name of the second service
build: server # specify the directory of the Dockerfile
ports:
- "3000:3000"
links:
- database
volumes:
- /path/in/host/machine:/path/in/container
database: # name of the third service
image: mongo
ports:
- "27017:27017"
Reference:
volumes in docker-compose

Resources