Is that possible to specify a static IP for docker container using docker-compose?
eth-java:
image:
registry-intl.ap-southeast-1.aliyuncs.com/einnity/coin-ethereum:1.0
container_name:
eth-java
ports:
- "8002:8198"
networks:
my-network:
ipv4_address: 192.168.1.21
And this container will communicate with
eth:
image:
ethereum/client-go
container_name:
eth
ports:
- "8545:8545"
- "30303:30303"
networks:
my-network:
ipv4_address: 192.168.1.17
volumes:
- /storage/eth/rinkeby:/root/.ethereum/rinkeby/
and the network settings is
networks:
my-network:
driver: bridge
ipam:
driver: default
config:
- subnet: 192.168.1.0/24
I type docker exec -it eth-java /bin/bash. Then I type curl and call RPC on 192.168.1.17:8545, it doesnt work. If don't hardcode the IP and use the dynamic IP, this will works. I just hate using dynamic IP because everytime when restarting the docker container, another IP will be given and I need to change my DB value every time.
Related
I have started learning about Docker and containers, and have been given an assignment to "Host a docker container on the external network (the one that the host is connected to) with its own IP address that is valid for said network".
As far as my understanding goes, Docker containers allow to forward ports onto the host, without exposing the docker container to the outside network. Is there any way to expose the whole container, with all its ports and have its own IP onto the external network?
Here is a excerpt from a test docker-compose.yaml file:
env20:
build: ./env20
image: env20
container_name: env20
hostname: env20
ports:
- "22:22/tcp"
- "80:80/tcp"
depends_on:
- mysql
networks:
gnet:
ipv4_address: 10.10.11.30
restart: unless-stopped
#############################################################
# Netowrk setup
#############################################################
networks:
gnet:
name: gnet
driver: macvlan
ipam:
driver: default
config:
- subnet: 10.10.11.0/24
gateway: 10.10.11.1
Any help would be appreciated!
I have two containers with different default networks and I want to communicate with each other. First I made a common network named "my_network" then enter into the container1's bash. I could ping the other container by name (container2) but when I tried to check the telnet with port 4000, I got the error:
telnet: Unable to connect to remote host: Connection refused
Curl request also didn't work. But, when I replaced the container name with the host's ip address (eg. 10.244.140.92), everything just worked fine. So what am I doing wrong?
My simplified compose:
version: "3.9"
networks:
my_network:
driver: bridge
external: true
default:
services:
container1:
image: ...
ports:
- 5000:80
- 5001:443
networks:
- default
- my_network
version: "3.9"
networks:
my_network:
services:
container2:
image: ...
ports:
- 4000:4000
networks:
- my_network
tl;dr I want every container in this stack to use the same IP & MAC address and be on my local network but need help on how to
For starters I'm new to docker and docker-compose. I made a docker-stack for my Plex Servers (three of them, one for movies by general categories/tv-shows, music, and holidays) with each one having its own IP address & MAC on my local network and now I want to make a second stack for some of my media management tools but this time I'd like the whole stack to use one IP address and MAC address but I haven't been able to figure out how to do it correctly/so it works
This is running on a QNAP NAS (TVS1282v3/QTS) but I am working through the CLI as I leaned that if I do a docker-compose through container station that it won't create the network for me
version: '2.4'
services:
Sonarr:
image: linuxserver/sonarr
container_name: Sonarr
environment:
- TZ=AMERICA/Denver
- name= Sonarr
volumes:
- /share/MediaManagement/Sonarr/config:/config:rw
- /share/MediaManagement/rip:/rip:rw
- /share/Plex:/Plex:rw
ports:
- 8989:8989
restart: unless-stopped
Radarr:
image: linuxserver/radarr
container_name: Radarr
environment:
- TZ=AMERICA/Denver
- name= Radarr
volumes:
- /share/MediaManagement/Radarr/config:/config:rw
- /share/MediaManagement/rip:/rip:rw
- /share/Plex:/Plex:rw
ports:
- 7878:7878
restart: unless-stopped
Lidarr:
image: linuxserver/lidarr
container_name: Lidarr
hostname: Lidarr
environment:
- TZ=AMERICA/Denver
- name= Lidarr
volumes:
- /share/MediaManagement/Lidarr/config:/config:rw
- /share/MediaManagement/rip:/rip:rw
- /share/Plex:/Plex:rw
ports:
- 8686:8686
restart: unless-stopped
networks:
qnet-static:
ipv4_address: 192.168.2.100
mac_address: 05:4A:AA:08:51:43
networks:
qnet-static:
driver: qnet
ipam:
driver: qnet
options:
iface: "eth0"
config:
- subnet: 192.168.2.0/23
gateway: 192.168.2.1
I have also tried it like how it was set up in my Plex compose file where I put
services:
NameOfService:
mac_address: 05:4A:AA:08:51:43
networks:
qnet-static:
ipv4_address: 192.168.2.100
....
networks: ##At the end, not in each service##
qnet-static:
driver: qnet
ipam:
driver: qnet
options:
iface: "eth0"
config:
- subnet: 192.168.2.0/23
gateway: 192.168.2.1
in each service but only the first container worked....
I also tried this at one point but still no luck/ it's syntax is wrong
networks:
qnet-static:
driver: qnet
ipam:
driver: qnet
options:
iface: "eth0"
config:
- subnet: 192.168.2.0/23
gateway: 192.168.2.250
ipv4_address: 192.168.2.100
mac_address: 05:4A:AA:08:51:43
Any help would be appreciate it as I am probably just missing a minor piece
Delete absolutely all of the networks: settings in the file. Don't try to manually assign IP address to containers or configure their MAC addresses.
Your containers will be accessible on your host's IP address, using the first ports: number for each. As far as other hosts on your network are concerned, the processes in containers will be indistinguishable from other services not running in containers.
You also do not need to manually set container_name: or hostname: in most circumstances. There are additional details of the Compose networking environment in Networking in Compose in the Docker documentation, though this mostly focuses on connections between containers. You usually don't need to think about the container-private IP address or (especially) the artificial MAC address within the container network environment.
Hi everyone i have create a network with mac-vlan type in docker because i wanted my containers to be on the same LAN as host.Now the strange thing which i have noticed is that when i stop and then restart a container with docker start command the container gets started but the IP assigned to it is the one that was assigned before the container was shutdown. doesn't IP change when containers are restarted furthermore the container is now not reachable because the IP its showing as its own has now been reassigned to another machine on the network from what i have read that the container is assigned the same IP as before but if the container couldn't get the IP it fails to start but my container is starting just fine. What am i missing here? on ubuntu version 17.10 docker version 17.11.0-ce Api version 1.34 (both client and server)
You should not use static IP's in docker unless you are working with something that allows routing from outside to the inside container, like in you're case 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.
That being said, you can achieve the above using docker-compose like below :
services:
mysql:
container_name: backend-database
image: mysql:latest
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
ports:
- "3306:3306"
networks:
mynetwork:
ipv4_address: 10.5.0.5
apache-tomcat:
container_name: apache-tomcat
build: tomcat/.
ports:
- "8080:8080"
- "8009:8009"
networks:
mynetwork:
ipv4_address: 10.5.0.6
depends_on:
- mysql
networks:
mynetwork:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
gateway: 10.5.0.1
Is there a way for setting a static IP on docker 1.7? I am currently running RedHat 6 so can only use Docker version up to 1.7.
The problem I am having is that default IP Docker defaults to an IP and its clashing with the one my server uses. Is there a way to specifically tell Docker to use a certain IP 127.0.0.2 for example?
You can use docker-compose to start up your containers. In that file you can define ipv4_address which will assign an static IP to your container. Here is an example
version: "2"
services:
SERVICE1:
image: $IMAGE_NAME
container_name: $CONTAINER_NAME
ports:
- "8080:8080"
networks:
mynet:
ipv4_address: 172.25.0.100
networks:
mynet:
driver: bridge
ipam:
config:
- subnet: 172.25.0.0/24