Service related commands
1. start-up docket
systemctl start docker
2. stop it docker service
systemctl stop docker
3. restart docker service
systemctl status docker
4. see docket Service status
systemctl status docker
5. Set boot up docker service
system enable docker
Mirror command :
1. Look up the mirror image : View all local images
docker images
docker images -q # Look at all the images of id
2. Search mirroring : Find the image you need from the network
docker serach Image name
3. Pull the mirror image : from Docker The warehouse downloads the image to the local , The image name format is name : Version number , If the version number does not specify that the rule is the latest version , If you don't know the mirror version , You can go to docket hub Search the corresponding image to see
docker pull Image name
4. delete mirror : Delete local image
docker rmi Mirror image id# Delete specified local image
docker rmi `docker images -q` # Delete all local mirrors
Container related orders :
1. Create a container
Create a container :docker run -it --name=c1 centos:7 /bin/bash
Parameters -i Indicates that the container is always running ,-t Means to assign a terminal , After creation , By the way, I logged in to the container , When ssh Exit time , The container will close
docker run -id --name=c2 centos:7
Parameters -d Means running in the background , After creation , Will not enter the container , adopt ssh After entering the container , Exit the container , The container will not close
Parameters :
-i: Keep the container running , Usually with -t Use at the same time . Join in it this 2 After a parameter , The container automatically enters the container after it is created , After exiting the container , The container closes automatically
-t: Reassign a pseudo input terminal to the container , Usually with -i Use at the same time
-d: To guard ( backstage ) Mode running container . Create a container to run in the background , Need to use docker exec Into the container . after , The container will not close
-it: The container you create is generally called an interactive container ,-id The container you create is generally called a guard container
--name: Name the container you created
2. Look at the container
docker ps: View the running container
docker ps -a# View all containers
3. Into the container :
docker exec Parameters # Exit the container , The container will not close
docker exec -it c2 /bin/bash
4. Start the container
docker start Container name
docker start c2
5. Closed container
docker stop Container name
docker stop c2
6. Delete container
If the container is running, the deletion fails , You need to stop the container to delete
docker rm c2
Delete all containers
docker rm `docker ps -aq`
7. View container information
docker inspect Container name
docker inspect c2
Data volume of container
Data volume :
- . Is a directory or file in the host
- When the container directory and the data volume directory are bound , The other party's changes will be synchronized immediately
- A data volume can be mounted by multiple containers at the same time
- Multiple data volumes can also be mounted at the same time
Configure data volume :
When you create a startup container , Use -v Parameters Set up the data volume
docker run ... -v Host directory file : Directory file in container ...
matters needing attention :
1. Directory must be an absolute path
2. If the directory does not exist , Automatically created
3. You can mount multiple data volumes
Example :docker run -it --name=c1 -v /root/data:/root/data_contailnet centos:7 /bin/bash
Configure the data volume container :
1. Create a start c3 Data volume container , Use -v Parameter setting data volume
docket run -it --name=3 -volumes centos:7 /bin/sh
2. Create a start c1 c2 Containers , Use --volumes-from Parameter setting data volume
docker run -it --name=c1 --volumes-from c3 centos:7 /bin/bash
docker run -it --name=c2 --volumes-form c3 centos:7 /bin/bash
Deploy mysql:
1. Search for mysql Mirror image
docker search mysql
2. Pull mysql Mirror image
docker pull mysql:5.6
3. Create a container , Set port mapping , Directory mapping
# stay /root Create under directory mysql Directories are used to store mysql Data and information
mkdir ~/mysql
cd ~/mysql
function mysql:
docker run -id \
-p 3307:3306 \
--name=c_mysql \
-v $PWD/confi:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:5.6
Parameter description :
-p 3307:3306: The container of 3306 The port maps to the host 3307 port
-v $PWD/conf:/etc/myql/conf.d: Will host the current directory of conf/my.cnf Ancient vessels /etc/mysql/my.cnf The configuration directory
-v$PWD/logs:/logs: Will host the current directory of logs Directory share disaster to container /logs Log directory
-v$PWD/data:/var/lig/myql: Will host the current directory of data The directory is attached to the container's /var/lib/mysql Data directory
-e MYSQL_ROOT_PASSWORD=123456: initialization root User's password
Tomcat Deploy :
1. Search for tomcat Mirror image
docker search tomcat
2. Pull tomcat Mirror image
docker pull tomcat
3. Create a container , Set port mapping , Directory mapping
# stay /root Create under directory tomcat Directories are used to store tomcat Data and information
mkdir ~/tomcat
cd ~/tomcat
4. start-up tomcat
docker run -id --name=c_tomcat \
-p 8080:8080 \
-v $PWD:/usr/local/tomcat/webapps \
tomcat
Parameter description :
-p8080:8080: The container of 8080 Port mapping to host's 8080 port
-v $PWD:/usr/local/Tomcat/webapps: Mount the current directory in the host to the current container webapps
Nginx Deploy :
1. Search for nginx Mirror image
docker search nginx
2. Pull nginx Mirror image
docker pull nginx
3. Create a container , Set port mapping , Directory mapping
# stay /root/ Create under directory nginx Directories are used for pure nginx Data and information
mkdir ~/nginx
cd ~/nginx
mkdir conf
cd conf
# stay ~/nginx/conf Create nginx.conf file , Paste the following
vim nginx.conf
docker run -id --name=c_nginx \
-p 80:80 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html
nginx
Parameter description :
-p 80:80: The container of 80 The port maps to the host 80 port
-v $PWD/config/nginx.conf:/etc/nginx/nginx.conf : Will host the current directory of /conf/nginx.conf Attached to the container :/etc/nginx/nginx.conff The configuration directory
-v $PWD/logs:/var/log/nginx: Will host the current directory of logs Directory share disaster to container /var/log/nginx Log directory
Deploy Redis
1. Search for redis Mirror image
docker search redis
2. Pull redis Mirror image
docker pull redis:5.0
3. Create a container , Set port mapping
docker run -id --name=c_redis -p 6379:6379 redis:5.0
4, Use an external machine to connect redis
./redis-cli.exe -h 192.168.149.135 -p 6379









