Before reading this article, you need to understand the concept of containerization, as well as the infrastructure and concepts of Docker
Installation environment
How can a good programmer not have his own test environment? Next, I will record the actual operation and build my own test environment step by step. Environment: Vm, centos7. x, docker-CE, firewall disabled.
- Install and disable the firewall on the VM
slightlyCopy the code
- The docker – ce installation
Lvm2 # step 2: y y y y y y y y y y y y y y y y y Add software source information sudo yum - config - manager - add - 'https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # Step 3 sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo # Step 4: Install docker-ce sudo yum makecache fast sudo yum -y install docker-ce # Step 4: Sudo systemctl enable Docker --nowCopy the code
- Docker image repository accelerates configuration and restarts the Docker service
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com"]
}
EOF
service docker restart
Copy the code
- validation
docker -v
Copy the code
At this point, the Docker runtime environment is ready
Running a simple container
Next, use docker to run the first container, using mysql as an example
Step 1: Docker central warehouse research
- Dockerhub found the official mysql image
- Extract key information
Starting a MySQL instance is simple: $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag Where to Store Data $ docker run --name Some - mysql - v/my/own/datadir: / var/lib/mysql - e MYSQL_ROOT_PASSWORD = my - secret - pw - d mysql: tag # and a lot about how to mount the configuration file, and some environment variables, Detailed Dockerfiles can also be viewed, taking only the most commonly used ones hereCopy the code
Step 2: Mirror pull and container operation
- Pull mysql image
docker pull mysql:latest
Copy the code
- Look at mirror
docker images
Copy the code
- Background running container
docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /root/mysql-data:/var/lib/mysql mysql:latest
Copy the code
- View running containers
docker ps
Copy the code
- Enter the mysql container to execute the SQL
Docker exec -it mysql mysql -uroot -p docker exec -it mysql -uroot -pCopy the code
Ok, at this point, a complete container is running. When the vm restarts, just use docker start mysql to start the mysql service.
Summary: All software images are identical, and in two simple steps, any software can be managed using Docker. Next, share docker network and data volume as well as Docker troubleshooting and some use tips, please look forward to ~ next: Docker advanced