In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Today, what the editor shares with you is the introduction and use of common commands in Docker containers. The article lists in detail the common commands in Docker and uses examples to show how to use them. Interested friends can use them for reference. I hope it will be helpful to you.
Docker common commands: mirror, container, network, data volume
Dockerfile example:
Dockerfile is a mirror description file that contains instructions, each of which builds a layer, so the content of each instruction is to describe how the layer should be built. Basic structure of Dockerfile:
-basic image
-maintainer information
-Image build instruction
-execute instructions when the container starts
FROM node:8
LABEL maintainer= "Jext Community, https://github.com/rickding/HelloDocker"
# copy files
COPY. / usr/node/
WORKDIR / usr/node/
# launch service
CMD ["node", "hello.js"]
EXPOSE 8010
Common Dockerfile directives:
Common commands for Docker-compose resource orchestration:
Docker-compose.yml example:
The resource orchestration file defines version information, services service configuration, networks network information, volumes volume information, and contains the container configuration for each service startup.
Version:'3'
Services:
Db:
Hostname: db
Image: mysql:5
Command:-- default-authentication-plugin=mysql_native_password
Ports:
-3306 3306
Environment:
MYSQL_DATABASE: starter
MYSQL_ROOT_PASSWORD: root
Api:
Image: starter_api:latest
Build:.
Ports:
-8011 Phantom 8011
Depends_on:
-db
Common docker-compose.yml directives:
Common commands for Swarm cluster deployment:
Skills for viewing logs logs
Log is very important in the operation of the system, development, testing and operation and maintenance find the cause of the fault through system log analysis. The logs command formats the log information in combination with grep:
Docker-compose logs-ft | grep-- color-I-e error-e warn-e version-e exception
The Docker three Musketeers logs command is sorted out as follows:
Docker prune cleans up system garbage
Based on the Linux kernel, Docker allocates and isolates resources through operating system and virtual container calls to CGroup, Namespace and other system interfaces. The basic architecture is as follows:
Docker relies on system resources to run, and some garbage will be generated in the process of allocation and recycling, for example, docker rm deletion is not performed after docker stop container. Run docker system df to view the resource information. RECLAIMABLE is the recyclable ratio:
Add the option-v to display details: docker system df-v
Tips: run the prune command to clean up the garbage and release resources:
Docker system prune-volumes
The prune commands provided by Docker are organized as follows:
Instance 1:Docker starts nginx
L code: https://github.com/rickding/HelloDocker/tree/master/nginx
Configuration and script files:
├── docker-compose.yml
├── build.sh
├── run.sh
├── stop.sh
L Dockerfile adds web pages and configuration files based on nginx images:
FROM nginx:stable
# web files
COPY. / web/ / usr/share/nginx/html
# config
COPY. / conf/nginx.conf / etc/nginx/nginx.conf
COPY. / conf/conf.d / etc/nginx/conf.d
WORKDIR / etc/nginx
EXPOSE 80
L build image: execute script. / build.sh or command: docker build-t nginx:latest.
L launch container instance: execute script. / run.sh or command: docker run-it-- name nginx-p 80:80-d nginx:latest
L visit http://localhost:80/ and see the page:
Stop deleting instances: execute script. / stop.sh or command: docker stop nginx & & docker rm nginx
Example 2: resource orchestration Web service
L code: https://github.com/jextop/StarterDeploy
Configuration and script files:
├── docker-compose.yml
├── pull.sh
├── up.sh
├── logs.sh
├── down.sh
L docker-compose.yml deploys multiple container instances on which Web service depends, including database, cache, message queue, log system, API interface and Web management backend:
Version:'3'
Services:
Db:
Hostname: db
Image: mysql:5
Command:-- default-authentication-plugin=mysql_native_password
Ports:
-3306 3306
Environment:
MYSQL_DATABASE: starter
MYSQL_ROOT_PASSWORD: root
Cache:
Hostname: cache
Image: redis:4
Command: redis-server-- appendonly yes
Ports:
-6379PUR 6379
Mq:
Hostname: mq
Image: webcenter/activemq:latest
Ports:
-61616purl
-8161 Phantom 8161
Elasticsearch:
Hostname: elasticsearch
Image: elasticsearch:latest
Ports:
-9200 purl 9200
-9300 purl 9300
Log:
Hostname: log
Image: registry.cn-shanghai.aliyuncs.com/hellodock/logstash:7.5.2
Ports:
-9600 purl 9600
-9601 Freund 9601
Depends_on:
-elasticsearch
Db_admin:
Image: adminer:latest
Ports:
-3006 purl 8080
Depends_on:
-db
Api:
Image: registry.cn-shanghai.aliyuncs.com/jext/starter_api:latest
Ports:
-8011 Phantom 8011
Depends_on:
-db
-cache
-mq
-log
Admin:
Image: registry.cn-shanghai.aliyuncs.com/jext/starter_admin:latest
Ports:
-8010 purl 8010
Depends_on:
-api
L start the Web service: execute the script. / up.sh or command: docker-compose up-d
L View the running instance: docker-compose ps
L View log: execute script. / logs.sh or command: docker-compose logs-ft
L visit http://127.0.0.1:8010/ and see the page:
L stop and delete services: execute script. / down.sh or command, docker-compose down-- remove-orphans
Example 3: cluster deployment of Web services
L code: https://github.com/jextop/StarterDeploy
Configuration and script files:
├── docker-compose.yml
├── pull.sh
├── deploy.sh
├── rm.sh
L docker-compose.yml adds deploy attribute, replicas specifies the number of copies, and placement specifies docker node:
Deploy:
Replicas: 1
# placement:
# constraints: [node.labels.group = = api]
L start Swarm to join the node to build a cluster, and the first node automatically becomes the administrator: docker swarm init
Deploy Web service: execute script. / deploy.sh or command: docker stack deploy-c docker-compose.yml starter
L View Stack and services: docker stack ls & & docker service ls
L stop deletion service: execute script. / rm.sh or command: docker stack rm starter
The above is the introduction and use of the common commands of the Docker container, and you need to use it yourself to understand the details. If you want to know more about it, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.