Introduction to Docker
Docker is a virtual environment container, which can package your development environment, code, configuration files, etc. into this container, publish and apply them to any platform. It can greatly improve the work efficiency of development, testing and operation and maintenance personnel, and there is no need to waste time on environmental configuration, user permissions and so on.
Three concepts of Docker
1. Image: similar to the image in virtual machine, it is a read-only template for Docker engine containing file system. Any application needs an environment to run, and the image is used to provide this running environment. For example, a cnetos image is a template containing centos operating system environment.
2. Container: similar to a lightweight sandbox, it can be regarded as a minimalist Linux system environment (including root permission, process space, user space, network space, etc.) and the applications running in it. Docker engine uses containers to run and isolate applications. Containers are application instances created by images. You can create, start, stop and delete containers. Containers are isolated from each other and do not affect each other. Note: the image itself is read-only. When the container starts from the image, docker creates a writable layer on the upper layer of the image, and the image itself remains unchanged.
3. Repository: similar to the code repository, this is the image repository, where Docker is used to store image files. Note the difference between the registration server and the registration server: the registration server is the place where the warehouse is stored. Generally, there are multiple warehouses; The warehouse is the place where images are stored. Generally, each warehouse stores one kind of image, and each image is distinguished by tag. For example, Ubuntu warehouse stores Ubuntu images of multiple versions (12.04, 14.04, etc.).
(ps: the concept quotes Xiaohu's article https://zhuanlan.zhihu.com/p/23599229# Docker installation)
In a simple and lovely way, the mirror image is a whale, each warehouse is a port, each container is a container, and the programmer is a dock worker. As like as two peas, the docker will pack the program in containers (containers) and pack them. Each container will not affect each other. Wharf workers will put containers on whale (mirror). Whale can travel around the world through ports (warehouses), and the containers (containers) will be identical. At the same time, whales can swim back and forth quickly in various ports to ensure the productivity of dockers.
Installation of Docker
Experimental environment: CentOS 8
1. After connecting to the remote server, delete the old version of docker in the environment. The current docker engine is called docker CE.
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
2. Install Yum utils package
sudo yum install -y yum-utils
3. Set up a stable repository
① docker has its own repository, but it will be slow
sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
② We can use Alibaba cloud's Mirror accelerator.
4. Start installing docker engine
sudo yum install docker-ce docker-ce-cli containerd.io
5. Start Docker.
sudo systemctl start docker
6. Verify that Docker Engine is installed correctly by running the Hello world image.
sudo docker run hello-world
Docker pull nginx
1. Query nginx image in warehouse
docker search nginx
2. Download nginx image
docker pull nginx
3. Start a simple nginx service through the nginx image of docker
docker run -it -d -p 80:80 --name zlx-ngnix nginx docker run -it -d -p [Mapping port] --name [Container name] nginx[edition(Can be specified)]
4. Set the security group on the ECS and open the port
5. After opening the port, we can view the page~
Enter your public IP on the web page, for example: 18.104.22.168
6. Access the page through nginx
① First, configure our nginx. Create a new folder. Conf and conf.d are used to save configuration files, html is used to place static files, and logs is used to save logs
mkdir -p /home/docker/nginx/conf/conf.d mkdir -p /home/docker/nginx/html mkdir -p /home/docker/nginx/logs
② Check our docker process and find the ID copy corresponding to the ZLX ngnix container
③ Copy the default configuration file in the container
docker cp [container ID]:/etc/nginx/nginx.conf /home/docker/nginx/conf/nginx.conf docker cp [container ID]:/etc/nginx/conf.d /home/docker/nginx/conf docker cp [container ID]:/usr/share/nginx/html /home/docker/nginx
④ After copying, stop and delete the container
docker stop [container ID] docker rm [container ID]
⑤ Start service
docker run \ -p 80:80 \ --name zlx-ngnix \ --restart=always \ -v /home/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \ -v /home/docker/nginx/conf/conf.d:/etc/nginx/conf.d \ -v /home/docker/nginx/html:/usr/share/nginx/html \ -v /home/docker/nginx/logs:/var/log/nginx \ -d \ nginx
⑥ Enter container, restart container, reload
docker exec -it container id /bin/bash docker exec -t container id nginx -t docker exec -t container id nginx -s reload
⑦ Add a hello.html file and display hello nginx on the page
cd /home/docker/nginx/html vim hello.html
⑧ View our page
Upload Docker image to cloud warehouse
1. Let's go to Alibaba cloud first Container mirroring service
2. Create personal instance, image warehouse and namespace
After success, you will get a mirror warehouse
3. Log in to Alibaba cloud Docker Registry according to the operating instructions
docker tag [container ID] registry.cn-hangzhou.aliyuncs.com/ipseach/acca:[Mirror version number] docker push registry.cn-hangzhou.aliyuncs.com/ipseach/acca:[Mirror version number]
4. After success, you can get an image version
5. You can pull your image again through the pull command
After a few days of rough learning, I have a deeper understanding of docker after using cloud services. It's great to have such a learning opportunity. I tested the image pulling of docker CE, container establishment, container testing, data volume and image uploading, and the simple operation of docker compose. I hope there will be more and more similar activities in the future, which can better help college students carry out practical operation. I hope the developer community will be better and better and provide more learning resources.docker pull registry.cn-hangzhou.aliyuncs.com/ipseach/acca:[Mirror version number]