1. Installation configuration:
1. Installation (centos7):
yum install docker -y
yum install curl -y
2. Configuration (centos7) is convenient for later development with spring-boot:
Open the /usr/lib/systemd/system/docker.service file and modify the ExecStart line.
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
Take effect after restart
systemctl daemon-reload
systemctl restart docker.service
test whether it works
curl http://127.0.0.1:2375/info
2. Basic commands:
1. Start|stop|restart:
systemctl start|stop|restart docker
2. Search for mirrors:
docker search java //Search for mirrors whose names contain java. The parts listed below show that the search matches NAME, DESCRIPTION
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io
docker.io/node Node.js is a JavaScript-based platform for... 5492 [OK]
docker.io docker.io/tomcat Apache Tomcat is an open source implementa... 1823 [OK]
docker. io docker.io/java Java is a concurrent, class-based, and obj... 1703 [OK]
docker.io docker.io/openjdk OpenJDK is an open-source implementation o... 938 [OK]
docker.io docker.io/ghost Ghost is a free and open source blogging p... 753 [OK]
docker.io docker.io/anapsix/alpine-java Oracle Java 8 (and 7) with GLIBC 2.23 over... 303 [OK]
docker.io docker.io/jetty Jetty provides a Web server and javax.serv... 240 [OK]
docker.io docker.io/couchdb CouchDB is a database that uses JSON for d... 202 [OK]
3、docker pull java//下载镜像,将下载NAME为java的镜像,即上面第3行
4. docker images //Display existing images
5. docker rmi e856e4f0e190 //Delete an image, note that the last string is the IMAGE ID , you need to use docker images to list it to see it; there may be dependencies, you need to delete it first Dependent mirrors.
6. docker build -t my-image . //Use Dockerfile to build an image. Note that the last dot indicates that the Dockerfile is in the current directory, and there are examples behind the Dockerfile. The principle is basically to create another image my-image according to an image.
7. docker run --name my-app -p 80:8080 -d my-image //Run the image instance, my-app instance name, my-image image name. 8. docker
stop|start|rm my-app //stop|start|delete an instance, pay attention to the deletion must stop first
2. Dockerfile:
FROM java //Indicates that
VOLUME is created based on the image java /tmp //Create a directory, because tomcat needs to use the temporary directory
ADD app.jar app.jar //Add app.jar in the same directory of Dockerfile to the image The name is app.jar
ENV JAVA_OPTS="" //Set the environment variable
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app. jar" ]//Run the command after startup
Of course, the configuration of Dockerfile is more than that. You can search for it yourself when you need it.