Demand background:
I want to use docker to isolate my host environment, to create an isolated blank new development environment, and make it have a fixed IP, in which I can freely update and download various compilation dependencies, containers with privileged permissions, the following is the operation concrete steps to achieve
View docker network related commands
Create a custom subnet and configure a fixed IP for the container through this subnet
docker network create --subnet=172.18.0.0/24 mynetwork
Create an empty container with privileged permissions and a fixed IP with the created network configuration
Here I use the ubuntu:latest image as the basis to create a new blank container, the name is redis, and the IP is specified as 172.18.0.32
docker run -itd --name=redis --privileged --network mynetwork --ip=172.18.0.32 ubuntu:latest /bin/bash
Log in to the created empty container
docker exec -it redis bash
Enter the container, remember to execute
apt-get update
Tips: If you don’t execute the above commands, you may not have many software packages and many commands. If you just apt-get install, you may get an error
E: Unable to locate package
View the IP of the created container
ifconfig