Docker - Assign an IP address to a container using the docker run --ip command

When creating or starting a container using the docker run command, the --ip option can be used to declare the IP address that will be assigned to the container. In this example, a container is created using the foo:latest image, and the container will have IP address

docker run --ip foo:latest


By default, if the --network option is not used, the container will use the default bridge network.

~]# docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
7e6e54bde697   bridge            bridge    local
8ba129869d06   host              host      local
1143f39a14ae   none              null      local


The docker network inspect command can be used to see that the default bridge network uses IP addresses in the subnet. Thus, if you do not include the --network option, you will need to use an IP address in the subnet range.

~]# docker network inspect bridge
        "Name": "bridge",
        "Id": "55b61b1a57f58bf3dc43b5262d6ed312ecd1ecc43a32e356d2f10edc1536a035",
        "Created": "2021-10-26T21:42:00.410817105-05:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                    "Subnet": "",
                    "Gateway": ""


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter bad3f in the box below so that we can be sure you are a human.