Docker Community Forums

Share and learn in the Docker community.

Docker-compose static ip(container linux to mac)

docker

(User10e32) #1

I have created successfully(all is working) docker-compose file in my linux virtualbox machine. Then I took it to my mac. After creating the containers I tried to access the webpage, but browser refused to access it. I then took official php container and tried that with this compose file, it is also not working in mac. I think the problem is the creation of a static ip, but can not figure out what I am doing wrong?

What am i doing wrong in this compose file(how can i create the static ip that works in mac)?
Why static ip works in linux, but not in mac?
For the future where can I find information about the differences of network creation to linux and mac host(how they different and why)?

My docker-compose file:

version: '2'
services:
    web:
        container_name: app1
        restart: always
        build:
          context: /home/docker/Documents/app1
          dockerfile: Dockerfile
        ports:
          - "80"
        depends_on:
          - db
        networks:
            vpcbr:
                ipv4_address: 10.5.0.5
        tty: true
    db:
        container_name: app1_db
        restart: always
        image: mysql:5.6
        ports:
          - "3306"
        networks:
            vpcbr:
                ipv4_address: 10.5.0.6
        environment:
          - MYSQL_ROOT_PASSWORD=root
          - MYSQL_DATABASE=magento2

networks:
    vpcbr:
        driver: bridge
        ipam:
          config:
            - subnet: 10.5.0.0/16
              gateway: 10.5.0.1

I have found this post from stackoverflow.com/. In it user @zainengineer writes that “Modern docker-compose will automatically create containers with static ip for you”. I can not understand, does that mean, when I create container using docker-compose v3 that the container ip is stored somewhere and because of that static ip is only in v2? I have not found any additional information about that in docker documentation.


(User10e32) #2

I got it working by removing “tty: true” - why I can use that in linux, but mac complains about it (how to diagnose or debug issues like that?).


(Jliu70) #3

Hi,

I don’t have an issue setting a static IP address on the Mac w/o the tty statement.

Here’s an example docker-compose.yml file which I use with no problem and it doesn’t have the tty statement.
NOTE: I do have a driver: default parameter which you don’t seem to have.

version: '2'

services:
  app:
    image: busybox
    command: ifconfig
    networks:
      app_net:
        ipv4_address: 172.18.18.10

networks:
  app_net:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "false"
    ipam:
      driver: default
      config:
      - subnet: 172.18.18.0/24
        gateway: 172.18.18.1

Hope this helps you.