i am trying to bind container with nginx to ip 172.16.238.10 , but for some reason docker ignores settings in docker-compose
#my docker-compose file
version: "3.9"
services:
nginx:
build: nginx/
ports:
- 80:80/tcp
volumes:
./dokcer/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
./dokcer/nginx/conf/hosts:/etc/hosts
./docker/project:/var/www/project
networks:
app_net:
ipv4_address: 172.16.238.10
php-fpm:
build: php-fpm/
ports:
- 9000:9000/tcp
volumes:
./dokcer/php-fpm/conf/www.conf:/usr/local/etc/php-fpm.d/www.conf
./dokcer/php-fpm/conf/hosts:/etc/hosts
./dokcer/project:/var/www/project
networks:
app_net:
ipv4_address: 172.16.238.11
networks:
app_net:
ipam:
driver: default
config:
- subnet: "172.16.238.0/24"
after build and launch, I look at the docker_app_net network and see that the nginx container has ip 172.16.238.2 although I expected it to be 172.16.238.10.
what could be the problem? I will be grateful for every answer because I am confused :c
Related
Please help me if it's possible.
I need to start 2 applications with a single database.
I have 2 applications. First domain.com, 2-nd api.domain.com. Each application has docker-compose.yaml files.
domain.com - CMS
version: "3.8"
services:
web:
container_name: domain_web
build:
context: ./docker/php
dockerfile: Dockerfile
working_dir: /var/www/html
#command: composer install
volumes:
- ./:/var/www/html
- ./docker/php/app.conf:/etc/apache2/sites-available/000-default.conf
- ./docker/php/hosts:/etc/hosts
networks:
domain:
ipv4_address: 10.9.0.5
networks:
domain:
driver: bridge
ipam:
config:
- subnet: 10.9.0.0/16
gateway: 10.9.
volumes:
bel_baza:
api.domain.com - Laravel 5.6
version: "3.8"
services:
web:
container_name: api_domain_web
build:
context: ./docker/php
dockerfile: Dockerfile
working_dir: /var/www/html
# command: composer install
volumes:
- ./:/var/www/html
- ./docker/php/app.conf:/etc/apache2/sites-available/000-default.conf
- ./docker/php/hosts:/etc/hosts
networks:
api_domain:
ipv4_address: 10.15.0.5
db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password
restart: always
container_name: api_domain_db
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: domain
MYSQL_USER: user
MYSQL_PASSWORD: user
volumes:
- api_domain_baza:/var/lib/mysql
- ./docker/db:/docker-entrypoint-initdb.d
networks:
api_domain:
ipv4_address: 10.15.0.6
phpmyadmin:
image: phpmyadmin
restart: always
container_name: api_domain_pma
networks:
api_domain:
ipv4_address: 10.15.0.7
redis:
image: redis:3.0
container_name: api_domain_redis
networks:
api_domain:
ipv4_address: 10.15.0.10
networks:
api_domain:
driver: bridge
ipam:
config:
- subnet: 10.15.0.0/16
gateway: 10.15.0.1
volumes:
api_domain_baza:
api_domain started successfully.
I need to connect domain.com with database api_domain_db. For connecting host, I used IP address 10.15.0.6. First application not connected to the database from 2nd application.
What is my problem?
How I can connect domain.com with the database of 2nd application?
your problem is your are using separate docker compose applications for each application. And by default those applications can not access each other inner parts:
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.
doc is here - https://docs.docker.com/compose/networking/
So it is like it creates separate network for each docker compose.
if you want them both to see each other inner part you can create external docker network as this:
docker network create --subnet 10.1.0.0/24 network_name
and then use that network in both docker compose like this:
networks:
default:
external:
name: network_name
services:
.....
if you need fixed IPs, you can define them as
app:
image: ...
networks:
default:
ipv4_address: 10.1.0.10
I have below sample docker-compose yml
version: '3'
services:
spark-master:
image: bde2020/spark-master:2.4.4-hadoop2.7
container_name: spark-master
ports:
- "8080:8080"
- "7077:7077"
environment:
- INIT_DAEMON_STEP=setup_spark
spark-worker-1:
image: bde2020/spark-worker:2.4.4-hadoop2.7
container_name: spark-worker-1
depends_on:
- spark-master
ports:
- "8081:8081"
environment:
- "SPARK_MASTER=spark://spark-master:7077"
- SPARK_CONTAINDER_IP = **here i want the ip address of above spark master**
is it possible? can anyone please help me
Update : we can get container ID using below command
docker ps --format "{{.ID}}" --filter "dockerhost"
but am not getting use this command return values and assign it to environment variable
as I said in the comments:
your another compose works just fine, maybe your worker started faster
than your master therefore you get the exceptions , see
docs.docker.com/compose/startup-order
other solution could be use fix IP adresses in your compose for your services:
myservice:
container_name: mycon
image: some:image
networks:
mynet:
ipv4_address: 172.28.1.10
networks:
mynet:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
Hi I'm new to docker containers. I have the following setup:
The docker host is running on a Linux server, it is running 4 apps:
reverse-proxy (nodejs-based)
frontend container
backend container
active mq container
All of them are running in my-network
Here is the problem, I would like to re-route every urls that come into the reverse-proxy to where it suppose to be. And restriction is I can't use re-write the reverse-proxy, because it is not worthy to re-write
The following are the docker-compose.yml files
version: '3'
services:
backend:
image: tomcat/test:first
ports:
- "8080:8080"
networks:
- my-network
volumes:
- "/home/lluo/app/myApp/target/MyApp/WEB-INF/classes/META-INF/config:/usr/local/tomcat/conf/myApp-configuration/"
depends_on:
- active_mq
active_mq:
image: active_mq/test:first
ports:
- "24043:24043"
networks:
- my-network
networks:
my-network:
external: true
version: '3'
services:
reverse_proxy:
container_name: proxy_container
image: reverse/proxy:docker
ports:
- "0.0.0.0:15009:15009"
networks:
- my-network
networks:
my-network:
external: true
version: '3'
services:
frontend:
image: template/frontend:after_merge_develop
container_name: fe_container
ports:
- "3000:3000"
networks:
- my-network
volumes:
- "/home/lluo/config.json:/app/dist/config.json"
networks:
my-network:
external: true
And I bind the network ipv4_address to be 0.0.0.0
Please help me resolve this issue, it's been days.
Thank you very much!
I have the docker-compose.yml file
web_server:
build: web_server/
ports:
- "8000:8000"
links:
- mongo
tty: true
environment:
SYMFONY__MONGO_ADDRESS: mongo
SYMFONY__MONGO_PORT: 27017
networks:
app_net:
ipv4_address: 172.16.238.10
ipv6_address: 2001:3984:3989::10
networks:
app_net:
driver: bridge
enable_ipv6: true
ipam:
driver: default
config:
-
subnet: 172.16.238.0/24
-
subnet: 2001:3984:3989::/64
mongo:
image: mongo:3.0
container_name: mongo
command: mongod --smallfiles
expose:
- 27017
I want to have a specifiy IP for my web_server for pass this in another applications.
But when I call command docker-compose up I recive the error:
ERROR: The Compose file '.\docker-compose.yml' is invalid because:
Unsupported config option for networks: 'app_net'
Unsupported config option for web_server: 'networks'
What is wrong?
I dont't known why you have this error but you can try to fix some points:
webserver networks must refer the networks declared below
you simplify your network configuration and start with ipv4 only
Here is a working configuration:
version: '2'
services:
webssl:
image: nginx:1.11.4-alpine
ports:
- "443:443"
- "80:80"
volumes:
- /data/nginx/webroot:/usr/share/nginx/html:ro
networks:
- dmz
networks:
dmz:
ipam:
driver: default
config:
- subnet: 172.77.0.1/24
ip_range: 172.77.0.0/24
gateway: 172.77.0.1
I'm trying to provide static IP address to containers. I understand that I have to create a custom network. I create it and the bridge interface is up on the host machine (Ubuntu 16.x). The containers get IP from this subnet but not the static I provided.
Here is my docker-compose.yml:
version: '2'
services:
mysql:
container_name: mysql
image: mysql:latest
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
ports:
- "3306:3306"
networks:
- vpcbr
apigw-tomcat:
container_name: apigw-tomcat
build: tomcat/.
ports:
- "8080:8080"
- "8009:8009"
networks:
- vpcbr
depends_on:
- mysql
networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
gateway: 10.5.0.1
aux_addresses:
mysql: 10.5.0.5
apigw-tomcat: 10.5.0.6
The containers get 10.5.0.2 and 10.5.0.3, instead of 5 and 6.
Note that I don't recommend a fixed IP for containers in Docker unless you're doing something that allows routing from outside to the inside of your container network (e.g. macvlan). DNS is already there for service discovery inside of the container network and supports container scaling. And outside the container network, you should use exposed ports on the host. With that disclaimer, here's the compose file you want:
version: '2'
services:
mysql:
container_name: mysql
image: mysql:latest
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
ports:
- "3306:3306"
networks:
vpcbr:
ipv4_address: 10.5.0.5
apigw-tomcat:
container_name: apigw-tomcat
build: tomcat/.
ports:
- "8080:8080"
- "8009:8009"
networks:
vpcbr:
ipv4_address: 10.5.0.6
depends_on:
- mysql
networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
gateway: 10.5.0.1
I was facing some difficulties with an environment variable that is with custom name (not with container name /port convention for KAPACITOR_BASE_URL and KAPACITOR_ALERTS_ENDPOINT). If we give service name in this case it wouldn't resolve the ip as
KAPACITOR_BASE_URL: http://kapacitor:9092
In above http://[**kapacitor**]:9092 would not resolve to http://172.20.0.2:9092
I resolved the static IPs issues using subnetting configurations.
version: "3.3"
networks:
frontend:
ipam:
config:
- subnet: 172.20.0.0/24
services:
db:
image: postgres:9.4.4
networks:
frontend:
ipv4_address: 172.20.0.5
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:latest
networks:
frontend:
ipv4_address: 172.20.0.6
ports:
- "6379"
influxdb:
image: influxdb:latest
ports:
- "8086:8086"
- "8083:8083"
volumes:
- ../influxdb/influxdb.conf:/etc/influxdb/influxdb.conf
- ../influxdb/inxdb:/var/lib/influxdb
networks:
frontend:
ipv4_address: 172.20.0.4
environment:
INFLUXDB_HTTP_AUTH_ENABLED: "false"
INFLUXDB_ADMIN_ENABLED: "true"
INFLUXDB_USERNAME: "db_username"
INFLUXDB_PASSWORD: "12345678"
INFLUXDB_DB: db_customers
kapacitor:
image: kapacitor:latest
ports:
- "9092:9092"
networks:
frontend:
ipv4_address: 172.20.0.2
depends_on:
- influxdb
volumes:
- ../kapacitor/kapacitor.conf:/etc/kapacitor/kapacitor.conf
- ../kapacitor/kapdb:/var/lib/kapacitor
environment:
KAPACITOR_INFLUXDB_0_URLS_0: http://influxdb:8086
web:
build: .
environment:
RAILS_ENV: $RAILS_ENV
command: bundle exec rails s -b 0.0.0.0
ports:
- "3000:3000"
networks:
frontend:
ipv4_address: 172.20.0.3
links:
- db
- kapacitor
depends_on:
- db
volumes:
- .:/var/app/current
environment:
DATABASE_URL: postgres://postgres#db
DATABASE_USERNAME: postgres
DATABASE_PASSWORD: postgres
INFLUX_URL: http://influxdb:8086
INFLUX_USER: db_username
INFLUX_PWD: 12345678
KAPACITOR_BASE_URL: http://172.20.0.2:9092
KAPACITOR_ALERTS_ENDPOINT: http://172.20.0.3:3000
volumes:
postgres_data:
If you are never seeing the static IP address set, perhaps it could be because you are using "docker compose up". Try using "docker-compose up".
When I use "docker-compose up" (with the hyphen) I now see the static IPs assigned.
networks:
hfnet:
driver: bridge
ipam:
driver: default
config:
- subnet: 192.168.55.0/24
gateway: 192.168.55.1
services:
web:
image: 'mycompany/webserver:latest'
hostname: www
domainname: mycompany.com
stdin_open: true # docker run -i
tty: true # docker run -t
networks:
hfnet:
ipv4_address: 192.168.55.10
ports:
- '80:80'
- '443:443'
volumes:
- '../honeyfund:/var/www/html'
I wasted a lot of time to figure that one out. :(
I realized, that the more convenient and meaningful way is to give the container a container-name.
You can use the name in the same docker network as source.
This helped me because the docker-containers had changing IPs and by this I can communicate with another container with a static name that I can use in config-files.