Docker containerized deployment practice-getting started

The previous article shared with you " Python web development from entry to abandonment " which mentioned development and deployment matters. As there are many students counseling, to give you a better understanding, it is going to put container is deployed as a series of to explain, Docker Getting Started in today give you a brief talk, we welcome the ongoing attention.

Docker is an open source container project based on the Go language. It has attracted widespread attention in the industry since its birth in 2013. It is a new container technology compared to the traditional LXC (Linux Container) technology.

The concept of Docker is to realize "Build, Ship and Run Any App Anywhere", which is similar to JAVA's "one package, run everywhere" purpose. Through Docker, we can do one-stop processing for application development, testing, deployment.

As the most popular technology for cloud computing, Docker has many advantages:

  1. Simple and easy to use

  2. Solve the problems of operation and maintenance environment and service scheduling

  3. Low CPU memory resource usage

  4. Cloud computing core technology

  5. Active community

Let's briefly introduce the installation and use of Docker

Docker installation

Docker can only run on 64-bit platforms at present. I remember that the team could not use Docker on the team server two years ago. This is probably the reason.

We can install it manually or by script, here we use script to install.

Ubuntu Linux installation:

sudo curl -sSL https://get.docker.com | sh  # 官方安装
sudo curl -sSL https://get.daocloud.io/docker | sh # 安装速度快,二选一
sudo service docker start

Just download Docker for Mac directly for Mac OS installation, and I won’t demonstrate it here.
https://docs.docker.com/v17.12/docker-for-mac/install/

In order to avoid using the root identity for Docker commands every time, you can add the current user to the group.

sudo usermod -aG docker USER_NAME

Basic concepts of Docker

After the installation is complete, it is time to talk about the basic concepts:

Docker image (image): Similar to a read-only template, the image is the basis for creating a Docker container (container).

Docker container (container): It is a sandbox environment. This environment is the mini Linux system. We mainly use containers to run and isolate different applications.

Docker repository (repository): This is similar to our version of the code repository, such as Github or Bitbucket, where the image files are centrally stored.

A warehouse often has multiple mirror files, which are mainly distinguished by tags. For speed and safety, we often build our own mirrored private warehouse.

The operations of warehouse and labeling, students familiar with Git can see that Docker is very similar to it, and it is very easy to get started.

Docker commonly used commands

After explaining the concept, let's talk about the common commands of Docker.

docker pull ubuntu:16.04 # 拉群镜像冒号后面是标签tag,不指定默认latest,强烈建议加上
docker images  # 列出本地已经有的镜像,注意image id很重要
docker tag ubuntu:16.04 myubuntu:product # 给镜像添加新标签,类似链接作用
docker inspect myubuntu:product # 获取镜像详细信息
docker rmi myubuntu:product # 这里删除可以用image id

docker run ubuntu:16.04 /bin/bash -c "while true; do echo 1; sleep 1; done" # 启动容器 容器ID(dd06064bf6c0)
docker stop dd06064bf6c0  # 停止容器 dd06064bf6c0为容器ID
docker exec -it 292586a3883f bash # 进入容器
docker rm 292586a3883f 删除容器

docker ps -a # 查看所有容器

Here we talk about creating a new mirror:

docker run -it ubuntu:16.04 bash # 1. 启动镜像
root@42e296cc9587:/# touch 123.txt 
docker commit -m "add 123.txt" 42e296cc9587 ubuntu:test123
sha256:99db484eac429a6413977903653396c226dcc9917346417e4153ea322dc6a5d0

docker push hub.yourdomain.com/ubuntu:test123 # 推送镜像到仓库

We can see the effect

b7cf808512f4d9b78c15f1f8ab9b9fc1.webp

There are actually many commands, such as docker import/save/laod, I won’t say too much about it. There are more commands we can use to docker -hoperate, and we will stop here for the introduction of common commands.

Containerized deployment practice, I plan to share in a series from basic operations to actual combat applications. Today is the first entry, and I will continue to share more related content later, from the introduction of containerization to deployment practice orchestration technology. Welcome everyone to continue Pay attention.


Guess you like

Origin blog.51cto.com/15009257/2552285