Common operation commands of docker

Posted by kslagdive on Thu, 27 Jan 2022 04:36:02 +0100

Install docker for win10

one https://hub.docker.com/ Download and install docker
2. Set image source: in docker setting interface: docker engine configuration:
"registry-mirrors": [ "https://tp6zbrdb.mirror.aliyuncs.com" ]
3. Download Image: https://hub.docker.com/ Click Explore, enter the image you want, and then copy the command to the local cmd window to download
 
 
Docker deployment jar package running
Mode 1:
1. Upload the jar to the specified directory of the server
2. Create Dockerfile file in this directory
FROM java:8
MAINTAINER laiqiaobo
ADD demo-0.0.1-SNAPSHOT.jar demo.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","demo.jar"]
#from java:8 # pull a docker image with jdk 1.8
#maintainer by bingo
# demo-0.0.1-SNAPSHOT.jar is the jar package you uploaded. Replace it with the name of the jar package
# demo.jar # is the name you rename the jar package and run it in the container
#expose the ports exposed by the container, that is, how many ports the jar runs in the container
#The command executed after the entrypoint container is started, Java - jar demo Jar starts jar
 
4. After creating the Dockerfile file, execute the command to build the image:
// Pay attention to the last` Indicates that the Dockerfile file is in the current directory. abc is the image name after construction
docker build -t abc .
5. After the image is successfully built, you can run the container
docker run -d --restart=always --name demo -p 8080:8080 abc
 This representation docker The container will restart automatically after it stops or the server is powered on
--restart=always -p Host port: container port
 
Mode 2
Run a jdk container, and then mount its directory to the host. After running, you can put the jars to be run under the mount directory of the host, and then re run the docker container each time. You only need to replace the jar package in the host for each release
 
1. Prepare jdk1 8 mirror image
2. Build the container and map the local directory
docker run -d --restart=always -v /C/develop/server:/jar  -p 8000:8001 --name=cdemo   primetoninc/jdk:1.8 java -jar -Duser.timezone=GMT+08 /jar/mybatis.jar
 
 -v Host Directory:docker Directory in, in win10 lower /C/representative c disc
primetoninc/jdk:1.8      Image name: version number
java -jar -Duser.timezone=GMT+08 /jar/mybatis.jar   Start command
 
Common commands
docker ps     // View containers in operation
docker ps -a     // View all containers
docker rm  xxx    // Delete container named xxx
docker start xxx   // Start xxx container
docker stop  xxx   // Stop container
docker stats Command to view the actual situation
docker exec -it bfc6039f87f7  /bin/bash     //Enter a container

// Modify the available memory size of the container
docker update -m 300m --memory-swap 1g bfc6039f87f7
Parameter interpretation
-d: Run the container in the background and return to the container ID;
--name="nginx-lb": Specify a name for the container;
-p: Specify port mapping host port:Container port
-m :Set the maximum memory used by the container, for example: -m 1g  perhaps -m 300M
-i: Run the container in interactive mode, usually with -t Simultaneous use;
-t: Reassign a pseudo input terminal to the container, usually with -i Simultaneous use;
--memory="300m" --memory-swap="1g"  Represents available memory 300 m,memory-swap Is 1 g
-m 300M --memory-swap -1     Represents available memory 300 m,memory-swap To set no upper limit,
If the values are the same, they cannot be used swap

docker run perhaps docker update
--cpuset-cpus=""    # Set of CPU s allowed 
    Example:--cpuset-cpus "0,6"  --cpuset-cpus "0-5"
-c,--cpu-shares=0    # CPU shared weight (relative weight)
--cpu-period=0    # Limit the cycle of CPU CFS from 100ms to 1s, i.e. [1000, 1000000]
    That is, the scheduling cycle. How often is it reassigned cpu
--cpu-quota=0    # Limit the CPU CFS quota, which must not be less than 1ms, i.e. > = 1000
    Set the content that can be used in each cycle CPU Time. For example: 4 cores cpu Scheduling 1 s, Quota 2 s,Equivalent to 50%cpu
    Set the number of containers that can be used in a scheduling cycle CPU Time is actually an upper limit. It doesn't mean that the container will be used for such a long time CPU Time.
--cpuset-mems=""    # Memory nodes (MEMs) that are allowed to execute on are only valid for NUMA architectures
The difference between docker run and docker start
docker run is only used when running for the first time. Put the image into the container. When starting the container again later, you only need to use the command docker start. It is equivalent to two steps: put the image into the container (docker create), and then start the container to turn it into a runtime container (docker start).
The function of docker start is to restart the existing image. You can use docker ps to find the information of the container.
 
 
 
 
Installing docker for linux
1, Environment
centos7 installed on local virtual machine
2, Install docker
yum install docker-engine
3, Enable Alibaba cloud acceleration
The image warehouse of docker is abroad, and the download will be slow. Enable Alibaba cloud acceleration.
Create daemon.com in / etc/docker directory JSON file, add the following

{
  "registry-mirrors": ["https://almtd3fa.mirror.aliyuncs.com"]
}
https://almtd3fa.mirror.aliyuncs.com It is the acceleration address of Alibaba cloud. After modification, restart docker

systemctl daemon-reload
service docker restart
4, Download java image
Download the java image. The tag is 8u111
docker pull java:8u111
5, Execute a runnable jar file
Test Put the jar in the / usr directory of the virtual machine, and then execute the command to start the jar.

docker run -d -p 9090:9090 -v /usr/springboot-1.jar:/usr/springboot-1.jar --name springboot java:8u111 java -jar /usr/springboot-1.jar

     -d Indicates starting in the background
     -p 9090:9090 Indicates that the port of the container is mapped to the port of the host, otherwise port 9090 cannot be accessed
     -v /usr/springboot-1.jar:/usr/springboot-1.jar Indicates that the host will be hosted jar File, mapped to container (path of host host before semicolon and path in container after semicolon)
     --name springboot It means taking a globally unique name for the container. Here I take the name springboot
    java:8u111 Represents the name and of the mirrored file tag
    java -jar /usr/springboot-1.jar Indicates operation jar Bag, note: here jar The package is the location in the container, which is through the front-v Attribute mapped

 

 

Topics: IDE