W
W
waltaki2021-03-23 13:31:31
linux
waltaki, 2021-03-23 13:31:31

How to forward a static IP to a container?

Hello.

At the moment I run the container with --net host, and applications can occupy any IP available on the machine itself.
I need to limit this, while leaving the ability to occupy any ports on a dedicated IP.

Now if I write docker run --net host --ip 6.192.35.15, it gives me

docker: Error response from daemon: user specified IP address is supported on user defined networks only.


When trying to create a network with this IP docker network create -d=overlay --subnet 6.192.35.15/32 host17, writes:
Error response from daemon: failed to allocate gateway (): No available addresses on this pool


How can this be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pfg21, 2021-03-23
@pfg21

forward the port inside the container and plus a rule to change the address for packets outgoing from the container.

A
Alexander, 2021-04-03
@MonsterCatz

Docker -compose will help you
Stop your containers
Create mycontainer.yml file

version: '2'
services:

myconteiner1: #Servicename
    image: imagename/imagename:1.0
    container_name: container-name1
    user: root
    networks:
      net:                                             - #Это имя сети
        ipv4_address: 172.19.0.2

myconteiner2: #Servicename
    image: imagename/imagename:1.0
    container_name: container-name2
    user: root
    networks:
      net:                                             - #Это имя сети
        ipv4_address: 172.19.0.3

networks:
  net:                                           - #Это имя сети      
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet:  172.19.0.0/24
    driver_opts:
      com.docker.network.bridge.name: common-bridge    -# Это имя моста

being in the directory that contains the
docker-compose file up -d
Shut down all containers described in the file - docker-compose down
View created docker networks docker-network ls

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question