In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article is about how to install and use Docker in centos7. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Install (take centos7 as an example) install yum install-y docker start service docker start verify installation docker version due to network problems, it may be very slow to pull the image, you can speed up by setting up agents and other operations Or build your own image warehouse and paste it to the warehouse center: Docker warehouse https://hub.docker.com/explore/ domestic: need to log in to https://cr.console.aliyun.com/#/imageListhttps://c.163.com/hub#/m/home/ instruction 1.docker pull [options] name [: TAG] pull image: untagged default get latest2.docker run [options] image [: TAG] [COMMAND] run image: there are many options for instruction Introduce the commonly used-d: background operation-p: specify port mapping-P: start all port mappings, need to check port mapping via docker ps-v: file mapping-e: variable assignment-m: limit the upper limit of container memory-name: container naming-restart=always: container restart 3.docker ps: view running containers-a: view all containers Including stopped 4.docker exec-it containid bash: go inside the container 5.docker stats containid: check the operation of the container 6.docker build-t image:tag-f buildfile.: build the image: sometimes we need to add new plug-ins to the existing image to rebuild the unique image, build and paste a self-built php image by writing Dockerfile (join the redis based on the basic php Plug-ins such as mq) docker build-t php:5.6-fpm-ext-f. / docker/php/phpDockerfile .phpDockerfile: FROM hub.c.163.com/library/php:5.6-fpmRUN apt-get update & & apt-get install-y libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng12-dev RUN docker-php-ext-install-j$ (nproc) iconv mcrypt RUN docker-php-ext-configure gd-- with-freetype-dir=/usr/include/-- with-jpeg-dir=/usr / include/ RUN docker-php-ext-install-j$ (nproc) gdRUN docker-php-ext-install mysqliRUN docker-php-ext-install pdo_mysqlRUN docker-php-ext-install zipRUN curl-L-o / tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/2.2.7.tar.gz\ & & tar xfz / tmp/redis.tar.gz\ & & rm-r / tmp/redis.tar.gz\ & & mkdir-p / usr / src/php/ext\ & & mv phpredis-2.2.7 / usr/src/php/ext/redis\ & & docker-php-ext-install redisCOPY. / docker/php/rabbitmq-c-0.4.1.tar.gz / tmp/rabbitmq-c-0.4.1.tar.gzRUN tar zxvf / tmp/rabbitmq-c-0.4.1.tar.gz\ & & curl-L-o / tmp/amqp-1.2.0.tgz http: / / pecl.php.net/get/amqp-1.2.0.tgz\ & & tar zxvf / tmp/amqp-1.2.0.tgz\ & & rm-r / tmp/rabbitmq-c-0.4.1.tar.gz\ & & rm-r / tmp/amqp-1.2.0.tgz\ & & mkdir-p / usr/src/php/ext\ & & mv rabbitmq-c-0.4.1 / usr/src/php/ Ext/rabbitmq\ & & mv amqp-1.2.0 / usr/src/php/ext/amqp\ & & cd / usr/src/php/ext/rabbitmq\ & &. / configure-- prefix=/usr/local/rabbitmq-c-0.4.1\ & & make & & make install\ & & cd / usr/src/php/ext/amqp\ & & docker-php-ext-configure amqp--with-php-config=/usr/local/bin / php-config-with-amqp-with-librabbitmq-dir=/usr/local/rabbitmq-c-0.4.1/\ & & docker-php-ext-install amqp question item
Firewall problem: a curl:no route to host problem occurred when calling the url of a container in the content of a container. After investigation: my centos7 firewall uses firewalld,firewall the bottom layer is to use iptables for data filtering, based on iptables, which may conflict with Docker. Solution: Port firewall-cmd-- zone=public-- add-port=80/tcp-- permanent is required to join the container in firewalld: join port 80 firewall-cmd-- reload: restart firewall
Permission issues: sometimes there are problems such as not being able to write files. Solution: (the roughest solution) add chmod 777-R * docker to the file and join docker run-- privileged=true
JAVA memory problem: there is a memory shortage when using springboot. Because the memory size of the unset jvm is directly used as the upper limit of the machine memory by default, the memory is tight. Adding docker run-m only limits the upper limit of the container's memory. After reaching the upper limit, the container will be stopped, but it will not affect the jvm's memory, so you should add java-Xmx256m-Xms64m-Xmn32m when starting the container. Of course, you can also set up jvm through other programs, depending on your personal preferences.
Code and image packaging problem: when using docker, whether the code needs to be built with the image to become a new image, this solution may be beautiful. After building, just run it where you need to pull it. However, in the process of practical application, the code of the business needs to be changed frequently, so the solution we choose is to map the code through-v, and the image is based on the running environment without code entry. In this way, if you change the code, you only need to replace the file. There is no need to rebuild the image.
Database problem: in our development and test docker also do mysql database, but read some introduction to the network, said that the database is not recommended to use docker, there may be problems. Due to the use of Aliyun's database in our production environment, no related pits have been found for the time being.
Application question: how to create, close, etc., containers for docker? Docker compose or shell? Considering that I had to add network problems to other customer installations, I scripted it directly in shell instead of compose. Finally, post some shell scripts of my non-professional operation and maintenance staff.
Correlation expansion
According to the network introduction of 1.docker, docker has three network types:
Bridge (default) Host NoneBridge: make a bridge port mapping. The container has an independent ip, port, and Host: the network in the container is the same as the host network.
2.docker compose manages multiple containers and defines the required containers by writing docker-compose.yaml
Installation: curl-L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname-s`-`uname-m`-o / usr/local/bin/docker-compose authorization: chmod + x / usr/local/bin/docker-compose View: docker-compose-- version
Post a docker-compose.yaml
Version: '2'services: java: build:. Ports:-"8080 depends_on 8080" volumes:-". / tmp:/tmp"-". / logs:/opt/logs" depends_on:-mysql entrypoint: ["sh", "- c" ". / wait-for-it.sh-h mysql-p 3306-s-- java $JAVA_OPTS-Djava.security.egd=file:/dev/./urandom-Dspring.datasource.url=jdbc:mysql://mysql:3306/mq-jar app.jar"] mysql: image: daocloud.io/mysql:5.6 environment: MYSQL_DATABASE: mq MYSQL_USER: mq MYSQL_PASSWORD: 123456 MYSQL_ROOT_PASSWORD: 123456
3.docker Visualization UI console controls container start and stop, running status and so on through visual pages. The more popular ones are dockerui,Shipyard and so on, depending on personal needs.
End
Finally, start the shell script for the container:
Echo "start docker" service docker startfunction start_image {if [$(docker ps-a | grep-c $1)-ge 1] then echo "container has exits $1 start" docker start $1 else echo "$1 run image create container" docker run-d-v / etc/localtime:/etc/localtime:ro-privileged=true-name $1 $2 fi} if [$(docker images hub.c.163.com/library/mysql:5.6 | grep-c hub.c.163. Com/library/mysql)-ge 1] then start_image cloud-mysql-dev\ "- p 8000 then start_image cloud-mysql-dev 3306-v ${PWD} / data/mysql:/var/lib/mysql-v ${PWD} / docker/mysql:/etc/mysql/conf.d-e MYSQL_ROOT_PASSWORD=123cloud hub.c.163.com/library/mysql:5.6" fiif [$(docker images hub.c.163.com/library/redis:3 | grep -) C hub.c.163.com/library/redis)-ge 1] then start_image cloud-redis-dev\ "- p 8001pur6379-v ${PWD} / data/redis:/data-v ${PWD} / docker/redis/redis.conf:/usr/local/etc/redis/redis.conf hub.c.163.com/library/redis:3 redis-server / usr/local/etc/redis/redis.conf-- appendonly yes" fi thank you for reading! This is the end of the article on "how to install and use Docker in centos7". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.