This article teaches you how to deploy common applications using Docker, consolidate your Docker command learning, the next article teaches you how to build our own Docker image.
Tomcat
Pull the mirror image.
docker pull tomcat
Copy the code
Create the container.
docker run -di --name tomcat -p 8080:8080 tomcat
Copy the code
Enter the container.
docker exec -it tomcat /bin/bash
Copy the code
Check to see if there is a ROOT project in the Webapps directory. The familiar Tomcat cat page is usually in this project.
As shown in the above, the directory is empty, actually Tomcat will default in a new edition of the ROOT project was put into the webapps. Dist, if you really want to visit http://192.168.10.10:8080/ to see the Tomcat cat, Copy it to webapps.
Visit: http://192.168.10.10:8080/ to see familiar faces.
Nginx
Pull the mirror image.
docker pull nginx
Copy the code
Create an Nginx container.
docker run -di --name nginx -p 80:80 nginx
Copy the code
Copy the configuration file in the container to the specified directory (please create the directory in advance).
#Create a directory
mkdir -p /mydata/docker_nginx
#Copy the configuration file in the container to the specified directory
docker cp nginx:/etc/nginx /mydata/docker_nginx/
Copy the code
Rename host /mydata/docker_nginx/nginx to /mydata/docker_nginx/conf
mv /mydata/docker_nginx/nginx/ /mydata/docker_nginx/conf
Copy the code
Terminates and deletes the container (the directory mount operation can only be set when the container is created).
docker stop nginx
docker rm nginx
Copy the code
Create an Nginx container and mount the /etc/nginx directory and the /mydata/docker_nginx/conf directory on the host.
docker run -di --name nginx -p 80:80 -v /mydata/docker_nginx/conf:/etc/nginx nginx
Copy the code
Visit the host: http://192.168.10.10:80/ The result is as follows:
MySQL
Pull the mirror image.
Docker pull mysql: 8.0.21Copy the code
Create the container.
docker run -di --name mysql8 -p 3306:3306 -v /mydata/docker_mysql/conf:/etc/mysql/conf.d -v / mydata docker_mysql/data: / var/lib/mysql - e MYSQL_ROOT_PASSWORD = 1234 mysql: 8.0.21Copy the code
-p
: indicates port mapping in the format of host mapping port: container running port.-e
: adds environment variablesMYSQL_ROOT_PASSWORD
Is the login password of user root.
To connect to MySQL in the container, you only need to connect to the IP address of the host + the specified mapping port.
You can also enter the container and open the client using the MySQL command.
#Into the container
docker exec -it mysql8 /bin/bash
#Use the MySQL command to open the client
mysql -uroot -p1234 --default-character-set=utf8
Copy the code
Redis
Pull the mirror image.
docker pull redis
Copy the code
Create the container.
docker run -di --name redis -p 6379:6379 redis
Copy the code
To connect to Redis in the container, you only need to connect to the IP address of the host + the specified mapping port.
MongoDB
Pull the mirror image.
docker pull mongo
Copy the code
Create the container.
docker run -di --name mongo -p 27017:27017 mongo
Copy the code
To connect to MongoDB in a container, you only need to connect to the IP address of the host + the specified mapping port.
Elasticsearch
Pull the mirror image.
Docker pull elasticsearch: 7.8.1Copy the code
Create a container and, for demonstration purposes, change the size of ES startup memory.
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx512m" -e "discovery.type=single-node" -di --name es -p 9200:9200 -p 9300:9300 5601-5601 - p - v/mydata/docker_es/plugins: / usr/share/elasticsearch/plugins elasticsearch: 7.8.1Copy the code
Install Chinese word segmentation.
#Into the container
docker exec -it es /bin/bash
#Install Chinese word segmentation
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.8.1/elasticsearch-analysis-ik-7.8.1.zip
#Restart the es
docker restart es
Copy the code
Visit: http://192.168.10.10:9200/ the results are as follows:
Install the head plugin
Pull the mirror image.
docker pull mobz/elasticsearch-head:5
Copy the code
Create the container.
docker run -di --name es-head -p 9100:9100 mobz/elasticsearch-head:5
Copy the code
Open the ElasticSearch -head page in your browser and fill in the elasticSearch address.
Elasticsearch: elasticSearch: elasticSearch. Yml: elasticSearch: elasticSearch: elasticSearch.
#Into the containerDocker exec -it Container ID or name /bin/bash#Modifying a Configuration File
vi config/elasticsearch.yml
Copy the code
Add the following to elasticSearch.yml.
#Cross-domain request configuration (so that third-party plug-ins like HEAD can request ES)
http.cors.enabled: true
http.cors.allow-origin: "*"
Copy the code
Restart the container.
docker restart es
Copy the code
Solr
Pull the mirror image.
docker pull solr
Copy the code
Create the container.
docker run -di --name=solr -p 8983:8983 solr
Copy the code
Visit: http://192.168.10.10:8983/solr/#/ the results are as follows:
RabbitMQ
Pull the mirror image.
docker pull rabbitmq
Copy the code
Create the container.
docker run -di --name rabbitmq -p 4369:4369 -p 5671:5671 -p 5672:5672 -p 15671:15671 -p 15672:15672 -p 25672:25672 rabbitmq
Copy the code
Enter the container and enable the management function.
#Into the container
docker exec -it rabbitmq /bin/bash
#Enable the RabbitMQ management function
rabbitmq-plugins enable rabbitmq_management
Copy the code
Visit: http://192.168.10.10:15672/ use guest login account password, and the results are as follows:
That’s the end of the application deployment exercise, and now it’s time to learn how to build our own Docker image.
This article is licensed under a Creative Commons attribution – Noncommercial – No Deductive 4.0 International license.
You can check out more Docker articles in the category below.
🤗 your likes and retweets are the biggest support for me.
📢 Scan code pay attention to Mr. Hallward “document + video” each article is equipped with a special video explanation, learning more easily oh ~