Installation command:
sudo apt-get update
sudo apt-get install docker.io
(If the installation fails, you can also refer to the following website to install: link)
Start command:
sudo service docker start
Test run hello-world:
sudo docker run hello-world
running result:
Running effect chart
Edit the daemon.json file:
sudo vim /etc/docker/daemon.json
Add the content of the Alibaba Cloud accelerated image address:
{" registry-mirrors":["https://alzgoonw.mirror.aliyuncs.com"]}
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker
Enter Alibaba Cloud's mirror warehouse to search for the mirror you want, link.
Alibaba Cloud Image Warehouse
Find the desired java basic mirror:
Java basic mirror
There is the corresponding version on the right, download the version you want (Note: the java here is all openjdk, not oracle
jdk)。
grammar:
docker pull [OPTIONS] NAME[:TAG|[@DIGEST](https://my.oschina.net/u/3392911)]
Description:
OPTIONS: parameters, such as'-a', download all versions of the mirror.
NAME: The name of the image, such as'java'.
TAG: is the version, such as'java:8u111', the 8u111 version of java.
Examples:
sudo docker pull java:8u111
(Note: If you do not specify the corresponding version, docker will automatically download the latest version.)
Run the command:
sudo docker images
image
FROM java #Basic mirroring
ADD application.yml application.yml #Add configuration file
ADD FaceWeb-1.0.2-SNAPSHOT.jar app.jar #Add the jar package of the project and rename it
EXPOSE 80 #Declare port
VOLUME /tmp #Define anonymous volume
# Entry point of the program
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar","--Dspring.config.location=application.yml"]
# Ubuntu time zone
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
(For details, please refer to: link)
slightly.
Create a folder on the server to store docker files, and send all the files to the server through the tool.
image
grammar:
docker build [OPTIONS] PATH | URL |-
OPTIONS description:
- f :Specify the Dockerfile path to be used;
- m :Set the maximum memory;
- - tag,-t:The name and label of the image, usually name:tag or name format; multiple tags can be set for a mirror in one build.
Examples:
sudo docker build -t faceweb .
(Note: For detailed syntax, please check: link)
image
After the compilation is complete, run to view the image, and you can see the just compiled image.
image
grammar:
sudo docker run [OPTIONS] IMAGE [COMMAND][ARG...]
OPTIONS description:
- d:Run the container in the background and return the container ID;
- p:Port mapping, the format is: host(Host)port:容器port;
- - name:"nginx-lb":Specify a name for the container;
- e username="ritchie":Set environment variables;
- P: Random port mapping.
(Note: For detailed syntax, please check: link)
Examples:
sudo docker run –name faceweb -d -p 80:80 faceweb
grammar:
sudo docker ps [OPTIONS]
OPTIONS description:
- a :Show all containers, including those that are not running;
- l :Display the recently created container.
(Note: For detailed syntax, please check: link)
Examples:
sudo docker ps -a
image
image
You can clearly see the port mapping and some detailed information of the container.
So far, the download, compilation and deployment of the docker container have been completed. The following is an introduction to some common operations of the container.
View the container and copy the container ID of the container.
sudo docker stop CONTAINER
sudo docker start CONTAINER
sudo docker restart CONTAINER
sudo docker rm CONTAINER
(Note: You need to stop the container before deleting it. The deletion is irreversible, please operate with caution.)
sudo docker logs [OPTIONS] CONTAINER
OPTIONS description:
- f :Trace log output;
- t :Show timestamp;
- - since :Display all logs of a certain start time;
- - tail :Only the latest N container logs are listed.
Examples:
sudo docker logs -f cd4c9b023c46
grammar:
sudo docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
OPTIONS description:
- i :Keep STDIN open even if it is not attached;
- t :Assign a pseudo terminal.
Examples:
sudo docker exec -it faceweb /bin/bash
image
grammar
sudo docker rmi [OPTIONS] IMAGE [IMAGE...]
OPTIONS description:
- f :Force deletion
- - no-prune :The process image of the image is not removed, it is removed by default.
Examples:
sudo docker rmi faceweb
(Note: All deletions are irreversible, please operate with caution.)
For all docker commands please refer to: link
Recommended Posts