If I use command docker-compose build, I'll get error that looks like:
ERROR: Validation failed in file './docker-compose.yml', reason(s):
Service 'php' configuration key 'expose' '0' is invalid: should be of
the format 'PORT[/PROTOCOL]'
I use the last version docker and docker-compose.
My docker-compose.yml has the next code:
application:
build: code
volumes:
- ./symfony:/var/www/symfony
- ./logs/symfony:/var/www/symfony/app/logs
tty: true
db:
image: mysql
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: symfony
MYSQL_USER: root
MYSQL_PASSWORD: root
php:
build: php-fpm
expose:
- 9000:9000
volumes_from:
- application
links:
- db
nginx:
build: nginx
ports:
- 80:80
links:
- php
volumes_from:
- application
volumes:
- ./logs/nginx/:/var/log/nginx
elk:
image: willdurand/elk
ports:
- 81:80
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns
volumes_from:
- application
- php
- nginx
I use an ubuntu 14.04
Could you tell me how is fix it?
You need to put the port definitions in quotes for short ports (2 digits). This is a result of the nature of YAML and the used parser in docker-compose.
application:
build: code
volumes:
- ./symfony:/var/www/symfony
- ./logs/symfony:/var/www/symfony/app/logs
tty: true
db:
image: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: symfony
MYSQL_USER: root
MYSQL_PASSWORD: root
php:
build: php-fpm
expose:
- "9000"
volumes_from:
- application
links:
- db
nginx:
build: nginx
ports:
- "80:80"
links:
- php
volumes_from:
- application
volumes:
- ./logs/nginx/:/var/log/nginx
elk:
image: willdurand/elk
ports:
- "81:80"
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns
volumes_from:
- application
- php
- nginx
Also the expose statement should come with a single number only and also be quoted.
Added all needed changes in the above.
Related
I'm new to traefik, and I can't figure why my configuration do not work as expected.
Here is the context :
2 front-end app, builded and copy/pasted into a nginx folder using Dockerfile
1 rest api, compiled and running with node using Dockerfile
1 postgres database and pgadmin
1 mongo database and mongo-express.
All of this is setup in a docker-compose.
Frontend Dockerfile:
FROM node:lts-alpine as build
WORKDIR /app/frontend-app1 -- frontend-app2 for the other
COPY package*.json ./
RUN npm install
COPY . ./
RUN npm run build
FROM nginx:alpine
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/frontend-app1/build /usr/share/nginx/html/frontend-app1
EXPOSE 3001 -- 3002 from frontend-app2
CMD ["nginx", "-g", "daemon off;"]
API Dockerfile:
FROM node:14-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
ARG NODE_ENV=qual
ENV NODE_ENV=${NODE_ENV}
EXPOSE 3000
CMD ["node", "dist/main"]
Docker-compose:
version: "3.8"
networks:
backend-network:
traefik-network:
name: traefik-network
external: true
services:
mongo:
container_name: wow_mongo
image: mongo
restart: always
ports:
- 27017:27017
networks:
- backend-network
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: xxx
MONGO_INITDB_DATABASE: xxx
MONGO_INITDB_USERNAME: xxx
MONGO_INITDB_PASSWORD: xxx
volumes:
- ./init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh
mongo-express:
container_name: wow_mongo_express
image: mongo-express
depends_on:
- mongo
restart: always
ports:
- 8081:8081
networks:
- traefik-network
- backend-network
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: xxx
ME_CONFIG_MONGODB_ADMINPASSWORD: xxx
ME_CONFIG_MONGODB_URL: mongodb://xxx:xxx#mongo:27017/
labels:
- "traefik.enable=true"
- "traefik.http.routers.mongo-express.rule=Host(`me-qual.xxx.com`)"
- "traefik.http.routers.mongo-express.entrypoints=web"
postgres:
container_name: wow_postgres
image: postgres
restart: always
ports:
- 5432:5432
networks:
- backend-network
environment:
POSTGRES_PASSWORD: xxx
POSTGRES_USER: xxx
POSTGRES_DB: xxx
pgadmin:
container_name: wow_pgadmin
image: dpage/pgadmin4
depends_on:
- postgres
restart: always
networks:
- traefik-network
- backend-network
ports:
- 5050:80
environment:
PGADMIN_DEFAULT_EMAIL: xxx
PGADMIN_DEFAULT_PASSWORD: xxx
labels:
- "traefik.enable=true"
- "traefik.http.routers.pgadmin.rule=Host(`pgadmin-qual.xxx.com`)"
- "traefik.http.routers.pgadmin.entrypoints=web"
- "traefik.docker.network=traefik-network"
traefik:
container_name: wow_traefik
image: traefik:v2.6
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- $PWD/traefik-conf/traefik.yml:/etc/traefik/traefik.yml
- $PWD/traefik-conf/acme.json:/letsencrypt/acme.json
labels:
- "traefik.enable=true"
- "traefik.http.routers.api.rule=Host(`traefik.xxx.com`)"
- "traefik.http.routers.api.service=api#internal"
- "traefik.http.routers.api.entrypoints=web"
- "traefik.http.routers.api.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=xxx:xxx"
# - "traefik.http.routers.traefik.tls.certresolver=letsencrypt"
# - "traefik.http.middlewares.strip-www.redirectregex.regex=^https?://(www\\.)(.+)"
# - "traefik.http.middlewares.strip-www.redirectregex.replacement=https://$${2}"
# - "traefik.http.middlewares.strip-www.redirectregex.permanent=true"
api:
container_name: wow_api
depends_on:
- postgres
- mongo
restart: unless-stopped
image: wow_api:1.0.0
build:
context: ../wow-api
dockerfile: Dockerfile
ports:
- 3000:3000
networks:
- traefik-network
- backend-network
labels:
- "traefik.enable=true"
- "traefik.http.routers.wow-api.rule=Host(`api-qual.xxx.com`)"
- "traefik.http.routers.wow-api.entryPoints=web"
admin:
container_name: wow_admin
# depends_on:
# - api
restart: always
image: wow_admin:1.0.0
build:
context: ../wow-admin
dockerfile: Dockerfile
ports:
- 3002:80
networks:
- traefik-network
labels:
- "traefik.enable=true"
- "traefik.http.routers.wow-admin.rule=Host(`admin-qual.xxx.com`, `www.admin-qual.xxx.com`)"
- "traefik.http.routers.wow-admin.entrypoints=web"
# - "traefik.http.routers.blog.middlewares=strip-www"
# - "traefik.http.routers.blog.tls=true"
# - "traefik.http.routers.blog.tls.certresolver=letsencrypt"
consultant:
container_name: wow_consultant
# depends_on:
# - api
restart: always
image: wow_consultant:1.0.0
build:
context: ../wow-consultant
dockerfile: Dockerfile
ports:
- 3001:80
networks:
- traefik-network
labels:
- "traefik.enable=true"
- "traefik.http.routers.wow-consultant.rule=Host(`consultant-qual.xxx.com`, `www.admin-qual.xxx.com`)"
- "traefik.http.routers.wow-consultant.entrypoints=web"
And my traefik config is simple since I can't manage to make it work without tls.
global:
sendAnonymousUsage: false
log:
level: "INFO"
format: "common"
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: true
swarmMode: false
watch: true
network: traefik-network
api:
dashboard: true
entryPoints:
web:
address: ":80"
# http:
# redirections:
# entryPoint:
# to: "websecure"
# scheme: "https"
# permanent: true
websecure:
address: ":443"
# http:
# tls:
# certResolver: "letsencrypt"
# certificatesResolvers:
# letsencrypt:
# acme:
# email: "xxx"
# storage: "/letsencrypt/acme.json"
# tlsChallenge: {}
I figure out to make traefik.my_domain.com to work and to log using basic auth.
I can also navigate throught my differents services using localhost:<PORT_BINDED>
But as soon as I want to reach, for example, a front end app, I get a Gateway timeout and can't manage to make it work if I don't specify the port.
For example, accessing to the frontend app which is related to the consultant service:
consulltant-qual.xxx.com result in a gateway timeout, but if I ask consulltant-qual.xxx.com:3001, I can access to my app.
Any help would be grateful,
Thanks
How can i add multiple ports
I have nodejs and django application
webapp:
image: "python-node-buster"
ports:
- "8001:8000"
command:
- python manage.py runserver --noreload 0.0.0.0:8000
networks:
- django_network
node:
image: "python-node-buster"
ports:
- "3000:3000"
stdin_open: true
networks:
- node_network
ngrok:
image: wernight/ngrok:latest
ports:
- 4040:4040
environment:
NGROK_PROTOCOL: http
NGROK_PORT: node:3000
NGROK_AUTH: ""
depends_on:
- node
- webapp
networks:
- node_network
- django_network
networks:
django_network:
driver: bridge
node_network:
driver: bridge
Assuming i get the url for node at http://localhost:4040/inspect/http
http://xxxx.ngrok.io
and in my nodejs application, i want to access
http://xxxx.ngrok.io:8001
for apis
How to configure this
I would like to implement a hot reloading functionality from development evinronement such that when i change anything in the source code it will reflect the changes up to the docker container by mounting the volume and hence see the changes live in my localhost.
Below is my docker-compose file
version: '3.9'
services:
server:
restart: always
build:
context: ./server
dockerfile: Dockerfile
volumes:
# don't overwrite this folder in container with the local one
- ./app/node_modules
# map current local directory to the /app inside the container
#This is a must for development in order to update our container whenever a change to the source code is made. Without this, you would have to rebuild the image each time you make a change to source code.
- ./server:/app
# ports:
# - 3001:3001
depends_on:
- mongodb
environment:
NODE_ENV: ${NODE_ENV}
MONGO_URI: mongodb://${MONGO_ROOT_USERNAME}:${MONGO_ROOT_PASSWORD}#mongodb
networks:
- anfel-network
client:
stdin_open: true
build:
context: ./client
dockerfile: Dockerfile
volumes:
- ./app/node_modules
- ./client:/app
# ports:
# - 3000:3000
depends_on:
- server
networks:
- anfel-network
mongodb:
image: mongo
restart: always
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD}
volumes:
# for persistence storage
- mongodb-data:/data/db
networks:
- anfel-network
# mongo express used during development
mongo-express:
image: mongo-express
depends_on:
- mongodb
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_ROOT_USERNAME}
ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_ROOT_PASSWORD}
ME_CONFIG_MONGODB_PORT: 27017
ME_CONFIG_MONGODB_SERVER: mongodb
ME_CONFIG_BASICAUTH_USERNAME: root
ME_CONFIG_BASICAUTH_PASSWORD: root
volumes:
- mongodb-data
networks:
- anfel-network
nginx:
restart: always
depends_on:
- server
- client
build:
context: ./nginx
dockerfile: Dockerfile
ports:
- '8080:80'
networks:
- anfel-network
# volumes:
# - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
networks:
anfel-network:
driver: bridge
volumes:
mongodb-data:
driver: local
Any suggestions would be appreciated.
You have to create a bind mount, this can help you
maybe someone can help me.
I have keycloak, my nodejs-server, and traefik all installed with docker-compose. Everything seemed to be fine until I called a route from my frontend to the nodejs API. No matter what I tried I get a 403 all the time. When the nodejs server is running not in a docker it works. Strange in my opinion.
Here my Docker Compose if it helps:
version: '3.8'
services:
mariadb:
image: mariadb:latest
container_name: mariadb
labels:
- "traefik.enable=false"
networks:
- keycloak-network
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_DATABASE=
- MYSQL_USER=
- MYSQL_PASSWORD=
command: mysqld --lower_case_table_names=1
volumes:
- ./:/docker-entrypoint-initdb.d
keycloak:
image: jboss/keycloak
container_name: keycloak
labels:
- "traefik.http.routers.keycloak.rule=Host(`keycloak.localhost`)"
- "traefik.http.routers.keycloak.tls=true"
networks:
- keycloak-network
environment:
- DB_DATABASE=
- DB_USER=
- DB_PASSWORD=
- KEYCLOAK_USER=
- KEYCLOAK_PASSWORD=
- KEYCLOAK_IMPORT=/tmp/example-realm.json
- PROXY_ADDRESS_FORWARDING=true
ports:
- 8443:8443
volumes:
- ./realm-export.json:/tmp/example-realm.json
depends_on:
- mariadb
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
labels:
- "traefik.http.routers.phpmyadmin.rule=Host(`phpmyadmin.localhost`)"
networks:
- keycloak-network
links:
- mariadb:db
ports:
- 8081:80
depends_on:
- mariadb
spectory-backend:
image: spectory-backend
container_name: spectory-backend
labels:
- "traefik.http.routers.spectory-backend.rule=Host(`api.localhost`)"
- "traefik.port=4000"
ports:
- 4000:4000
networks:
- keycloak-network
depends_on:
- mariadb
- keycloak
spectory-frontend:
image: spectory-frontend
container_name: spectory-frontend
labels:
- "traefik.http.routers.spectory-frontend.rule=Host(`spectory.localhost`)"
ports:
- 4200:80
depends_on:
- mariadb
- keycloak
- spectory-backend
traefik-reverse-proxy:
image: traefik:v2.2
command:
- --api.insecure=true
- --providers.docker
- --entrypoints.web-secure.address=:443
- --entrypoints.web.address=:80
- --providers.file.directory=/configuration/
- --providers.file.watch=true
labels:
- "traefik.http.routers.traefik-reverse-proxy.rule=Host(`traefik.localhost`)"
ports:
- "80:80"
- "443:443"
- "8082:8080"
networks:
- keycloak-network
volumes:
- ./traefik.toml:/configuration/traefik.toml
- /var/run/docker.sock:/var/run/docker.sock
- ./ssl/tls.key:/etc/https/tls.key
- ./ssl/tls.crt:/etc/https/tls.crt
networks:
keycloak-network:
name: keycloak-network
I also tried static ip addresses for nodejs and keycloak -> didn't work.
Here on StackOverflow someone mentioned using https would help -> didn't work
Pretty much my situation: Link . The goal for me is that even the API is reachable through traefik
Btw my angular frontend can communicate with keycloak. Also in a docker. I can also ping the keycloak docker from the nodejs docker. Nodejs configuration parameters directly form keycloak.
I really don't know what to do next.
Did someone tried something similar?
I would like to know if it's possible to use my docker container name as host instead of the IP.
Let me explain, here's my docker-compose file :
version : "3"
services:
pandacola-logger:
build: ./
networks:
- logger_db
volumes:
- "./:/app"
ports:
- 8060:8060
- 10060:10060
command: npm run dev
logger-mysql:
image: mysql
networks:
- logger_db
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: Carotte1988-
MYSQL_DATABASE: logger
MYSQL_USER: logger-user
MYSQL_PASSWORD: PandaCola-
ports:
- 3306:3306
adminer:
networks:
- logger_db
image: adminer
restart: always
ports:
- 8090:8090
networks:
logger_db: {}
Sorry the intentation is a bit messy
I would like to set the name of my logger-mysql in a the .env file of my webservice (the pandacola-logger) instead of his IP adress
here's the .env file
HOST=0.0.0.0
PORT=8060
NODE_ENV=development
APP_NAME=AdonisJs
APP_URL=http://${HOST}:${PORT}
CACHE_VIEWS=false
APP_KEY=Qs1GxZrmQf18YZ9V42FWUUnnxLfPetca
DB_CONNECTION=mysql
DB_HOST=0.0.0.0 <---- here's where I want to use my container's name
DB_PORT=3306
DB_USER=logger-user
DB_PASSWORD=PandaCola-
DB_DATABASE=logger
HASH_DRIVER=bcrypt
If you can tell me first, if it's possible, and then, how to do it, it would be lovely.
By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
Reference
For Example:
version: '2.2'
services:
redis:
image: redis
container_name: cache
expose:
- 6379
app:
build: ./
volumes:
- ./:/var/www/app
ports:
- 7731:80
environment:
- REDIS_URL=redis://cache
- NODE_ENV=development
- PORT=80
command:
sh -c 'npm i && node server.js'
networks:
default:
external:
name: "tools"