Outline
DockerLinux installation
Docker introduction
Docker official document
dockerGitHub address
Docker is an open source application container engine, based on the Go language and open source in compliance with the Apache2.0 protocol.
Docker allows developers to package their applications and dependent packages into a lightweight, portable container, and then publish it to any popular Linux machine, which can also be virtualized.
Containers use the sandbox mechanism completely, and there will be no interfaces between each other (apps similar to iPhone), and more importantly, the container performance overhead is extremely low.
docker thinking
1. Container
2. Standardization -> transportation, storage, API interface
3. Isolation
Features:
1. Deliver your applications quickly and consistently
2. Responsive deployment and expansion
3. Run more workloads on the same hardware
What problem does docker solve
1. Solve the inconsistency of the operating environment
2. Solve the application isolation
3. Solve the scalability of server resources
Docker principle
Mirror image
runoob@runoob:~$ docker images
REPOSITORY | TAG | IMAGE ID | CREATED | SIZE |
---|---|---|---|---|
ubuntu | 14.04 | 90d5884b1ee0 | 5 days ago | 188 MB |
php | 5.6 | f40e9e0f10c8 | 9 days ago | 444.8 MB |
nginx | latest | 6f8d099c3adc | 12 days ago | 182.7 MB |
mysql | 5.6 | f2e8d6c772c0 | 3 weeks ago | 324.6 MB |
httpd | latest | 02ef73cf1bc0 | 3 weeks ago | 194.4 MB |
ubuntu | 15.10 | 4e3b13c8a266 | 4 weeks ago | 136.3 MB |
hello-world | latest | 690ed74de00f | 6 months ago | 960 B |
training/webapp | latest | 6fae60ef3446 | 11 months ago | 348.8 MB |
The above are mirrors one by one, which can be run directly through commands
warehouse
Central mirror warehouse: just pull the mirror on the machine that needs to be installed.
Domestic mirror warehouse: Ali mirror warehouse, NetEase Fengchao, etc., all need to be registered, and they can also publish their own mirrors.
container
To access the services running in the docker container through the network port, you can specify the port mapping through the -P or -p parameter.
1. Create an application:
Create a container for a python application.
runoob@runoob:~$ docker run -d -P training/webapp python app.py
fce072cc88cee71b1cdceb57c2821d054a4a59f67da6b416fceb5593f059fc6d
2. Bind port: -p : is the internal port of the container to be bound to the specified host port.
docker run -d -p 5000:5000 training/webapp python app.py
3. Container binding host network address
runoob@runoob:~$ docker run -d -p 127.0.0.1:5001:5000 training/webapp python app.py
4. Run the container
docker run -d -p 127.0.0.1:5000:5000/udp training/webapp python app.py
5. Visit
6. Check the binding status
docker port adoring_stonebraker 5000
7. Specify the container name
runoob@runoob:~ $ docker run -d -P --name runoob training/webapp python app.py
8. Create a new docker network
$ docker network create -d bridge test-net
9. Bind the application to the newly created network. Other containers can be moved to the network.
docker run -itd --name test1 --network test-net ubuntu /bin/bash
10. Ping between containers to check whether the network is Interworking
Configure DNS:
Add the following to the host's /etc/docker/daemon.json file to set the DNS of all containers: +
{ "dns": [ "114.114.114.114", "8.8.8.8" ] } Start the container The DNS will be automatically configured as 114.114.114.114 and 8.8.8.8. After configuration, you need to restart docker to take effect. View the status of DNS: docker run -it --rm ubuntu cat etc/resolv.conf 11. Set DNS for the specified container: docker run -it --rm -h host_ubuntu --dns=114.114.114.114 --dns-search= Test.com ubuntu parameter description: --rm: automatically clean up the file system inside the container when the container exits. -h HOSTNAME or --hostname=HOSTNAME: Set the hostname of the container, it will be written to /etc/hostname and /etc/hosts in the container.
--Dns=IP_ADDRESS: Add a DNS server to the container's /etc/resolv.conf, and let the container use this server to resolve all hostnames that are not in /etc/hosts.
--Dns-search=DOMAIN: Set the search domain of the container. When the search domain is set to .example.com, when searching for a host named host, DNS will not only search for host but also host.example.com.