Specify container IP when Docker creates container

Source: Internet
Author: User

When Docker creates a container, it uses the bridge network by default, assigning its own IP and not allowing itself to be specified.

In the actual deployment, we need to specify the container IP, not allow its own IP, especially when building a cluster, fixed IP is required.

We can create our own bridge network: MyNet, when you create a container, specify the network as MyNet and specify the IP.

View Network mode

Docker Network LS

Create a new bridge network

Docker Network create--driver bridge--SUBNET=172.18.12.0/16--gateway=172.18.1.1 mynet

View network Information

Docker Network Inspect MyNet

Create a container and specify the container IP

Docker run-e tz= "Asia/shanghai"--privileged-itd-h hadoop01.com--name hadoop01--network=mynet--ip 172.18.12.1 CentOS /usr/sbin/init

Running the container

Docker exec-it Hadoop01/bin/bash

CentOS minimized installation without Ifconfig command, can be installed via Yum

Yum Install-y Net-tools

Installing the SSH Service

Yum Install-y openssh-server

Yum Install-y openssh-clients

Systemctl Start Sshd.service

New non-root user

Useradd Brock

passwd Brock

Through local client access (specify a port or configure a standalone IP by creating a container)

Docker run-e tz= "Asia/shanghai"-P 6001:22--privileged-itd-h hadoop01.com--name hadoop01--network=mynet--ip 172.18. 12.1 Centos/usr/sbin/init

Or

Route-p add 172.18.12.0 MASK 255.255.255.0 10.0.75.2

Specify container IP when Docker creates container

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.