04 Docker/Infrastructure - The Road to DevOps

04 Docker/Infrastructure - The Road to DevOps

Article Github address, welcome start: https://github.com/li-keli/DevOps-WiKi

Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的、可移植的、自给自足的容器。开发者在笔记本上编译测试通过的容器可以批量地在生产环境中部署,包括VMs(虚拟机)、bare metal、OpenStack 集群和其他的基础应用平台。 

Docker is usually used in the following scenarios:

  • Automated packaging and publishing of web applications;
  • Automated testing and continuous integration, release;
  • Deploy and tune databases or other background applications in a service-based environment;
  • Build your own PaaS environment by compiling or extending an existing OpenShift or Cloud Foundry platform from scratch.

Docker installation:

wget -O /etc/yum.repos.d/docker-ce.repo  https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo && \
yum makecache && \
yum install docker-ce -y

Docker documentation:

In the infrastructure design scenario, I mainly use it to do it 自动化测试和持续集成、发布, but in the production scenario, it is generally not a single-node Docker operation, but a cluster operation.

Docker and Gitlab are now integrated. The normal integration is to select Docker as the runner when the Runner is registered. However, here we first select the shell and use the shell to understand how a single Docker image is generated, and then how to generate it. of a container.

Here is a simple .gitlab-ci.ymlscript:

deploy_api:
 stage: deploy
 tags:
   - Build
 script:
   - dotnet publish Test.Api.csproj -c Release -o ../../publish.api/
   - docker build -t test/api:v1 . 
   - docker run -d -P 8001:80 test/api:v1 --name test_api_server
 only:
   - master

This script packages the published dotnet core project to generate a docker image, and then runs the docker image in the background.

Use the command:

docker ps 

test_api_serverYou can see that the container named is running in the console output , and the port 8001 is exposed.

Here is a simple association. In fact, Docker CLI has many very rich functions, which need to refer to the official documents to practice by yourself

In addition, due to the limited knowledge of the author himself, he is all groping, so not all practices are correct, or some practices will have better solutions. I hope readers will correct me. If you have any questions, please leave issues .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325075378&siteId=291194637