What is Docker?
- Docker is an open source application container engine, which is based on Go language and complies with Apache 2.0 0 protocol is open source.
- Docker allows developers to package their applications and dependency packages into a lightweight and portable container, and then publish them to any popular Linux machine. It can also realize virtualization.
- Containers completely use the sandbox mechanism, and there will be no interfaces between them (similar to iPhone app s). More importantly, the performance overhead of containers is very low.
- After version 17.03, Docker is divided into CE (Community Edition) and EE (Enterprise Edition). We can use the Community Edition.
Advantages of Docker
- Docker is an open platform for developing, delivering and running applications. Docker enables you to separate your applications from your infrastructure so that you can deliver software quickly.
- With Docker, you can manage your infrastructure the same way you manage your applications. By using Docker's method to quickly deliver, test and deploy code, you can greatly reduce the delay between writing code and running code in a production environment.
Docker architecture
- Image: Docker image is equivalent to a root file system. For example, the official image ubuntu:16.04 contains a complete set of Ubuntu 16 04 root file system of the smallest system.
- Container: the relationship between an Image and a container is like a class and instance in object-oriented programming. An Image is a static definition, and a container is an entity when the Image runs. Containers can be created, started, stopped, deleted, paused, and so on.
- Repository: a repository can be regarded as a code control center for storing images.
Docker installation steps
Install Docker dependency package
sudo yum install -y yum-utils sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
Install Docker
sudo yum install docker-ce docker-ce-cli containerd.io
Start Docker
sudo systemctl start docker # View Docker status sudo systemctl status docker #View Docker version docker -v
Set Docker startup
sudo systemctl enable docker
Configuring alicloud image acceleration
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://3c8cr4xv.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
Docker installation mysql
#Official image address https://hub.docker.com/ #Download command docker pull mysql:5.7
Docker starts Mysql
sudo docker run -p 3306:3306 --name mysql \ -v /mydata/mysql/log:/var/log/mysql \ -v /mydata/mysql/data:/var/lib/mysql \ -v /mydata/mysql/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:5.7 #Detailed explanation of parameters The password is root Parameters: • -p 3306:3306: Map the 3306 port of the container to the 3306 port of the host • --name: Name the container mysql, If you name it mysql11 mysql22 All right • -v /mydata/mysql/log:/var/log/mysql: Mount the configuration file to the host/mydata/.. No need to enter docker Medium mysql File. hold docker In container Mysql File mount to external linxu In the file. • -e MYSQL_ROOT_PASSWORD=root: initialization root The user's password is root. -d It operates in the background mode, mysql:8.0 So mysql 8.0 Mirror boot container for. After each sentence \ Is a newline flag.
Modify the encoding format of mysql
Enter the attached mysql configuration directory
cd /mydata/mysql/conf
After entering, there are no files. We can edit and create them
vi my.cnf
Enter the following
[client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve
Restart mysql
docker restart mysql
View profile content
docker exec -it mysql /bin/bash cd /etc/mysql cat my.cnf
Dock install redis
Pull image
docker pull redis
docker starts redis
Create redis profile directory
mkdir -p /mydata/redis/conf touch /mydata/redis/conf/redis.conf
Start redis container
docker run -p 6379:6379 --name redis \ -v /mydata/redis/data:/data \ -v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \ -d redis redis-server /etc/redis/redis.conf
Enter redis console test
docker exec -it redis redis-cli
Configure persistence and password for redis
# Enter the configuration file directory cd /mydata/redis/conf # Enter configuration file vim redis.conf #Configuration persistence appendonly yes #redis password requirepass password
Restart docker
docker restart redis
Set docker container self start
# mysql docker update mysql --restart=always #redis docker update redis --restart=always
Docker installation rabbitmq
Pull image
docker pull rabbitmq:management
Create and start a container based on the downloaded image
sudo docker run -p 5671:5671 -p 5672:5672 -p 4369:4369 -p 25672:25672 -p 15671:15671 -p 15672:15672 --name rebbitmq -d rabbitmq:management
Port details
436925672 (Erlang discovery cluster port)
56725671 (AMQP port)
15672: (Web management background port)
61361614(STOMP protocol port)
1883 8883(MQTT protocol port)
Restart rabbitmq
docker restart rebbitmq
Self restart
docker update rebbitmq --restart=always
Open the web management side
# Access address http://ip address: 15672 # Default user name and password user name:guest password:guest
Delete container
Stop the container before deleting it
# View running containers docker ps # Stop a running container docker stop container id #Delete container docker rm container id
delete mirror
Delete the container before deleting the mirror
# View mirror docker images #delete mirror docker rmi image id