Deploy springboot project through docker under Ubuntu

Install docker under Ubuntu

installation##

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 up##

Start command:

sudo service docker start

test##

Test run hello-world:

sudo docker run hello-world

running result:

Running effect chart

Set up docker image acceleration#

Add mirror acceleration address##

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"]}

Restart service##

sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker

Download the basic image#

Search mirror##

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)。

Download mirror##

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.)

View local mirror##

Run the command:

sudo docker images

image

Write Dockerfile

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)

Modify the project configuration application.yml

slightly.

Compile image#

upload files##

Create a folder on the server to store docker files, and send all the files to the server through the tool.

image

Compile##

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

Start the container#

Run command##

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
  1. View running containers

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.

Common container operation commands#

View running containers##

View the container and copy the container ID of the container.

Stop the container##

sudo docker stop CONTAINER

Start the container##

sudo docker start CONTAINER

Restart the container##

sudo docker restart CONTAINER

Delete container##

sudo docker rm CONTAINER

(Note: You need to stop the container before deleting it. The deletion is irreversible, please operate with caution.)

View the log of the container##

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

Enter the container##

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

Common operations of mirroring#

Delete mirror##

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

Deploy springboot project through docker under Ubuntu
Deploy FTP server under ubuntu
Deploy the mail system under Ubuntu 19.10
Install and deploy Gerrit under Ubuntu
Installation of Docker CE under Ubuntu
Deploy django application in ubuntu through nginx+uwsgi
ubuntu18.04 install docker
How to quickly deploy docker on ubuntu server
Publish the node.js project under Ubuntu to heroku
docker install ubuntu
Install apache+PHP under Ubuntu
Install node.js under Ubuntu
Deploy GitBook under CentOS7
ubuntu16.04 deploy GPU environment
Install python3.6 under Ubuntu 16.04
Install docker on Ubuntu
Install mysql under Ubuntu 16.04
Install Thrift under ubuntu 14.10
Install OpenJDK10 under Ubuntu
Python MySQLd under Ubuntu
Install Docker on ubuntu18.04
Start working under ubuntu
[python] python2 and python3 under ubuntu
Use iptables under ubuntu
2018-09-11 Install arduino under Ubuntu
LNMP installation under Ubuntu
Network configuration under Ubuntu
Deploy JDK+Tomcat8 under CentOS
Install ROS under ROS Ubuntu 18.04[2]
Install MySQL under Ubuntu
Install Yarm-PM2 under Ubuntu
Install Docker on Ubuntu18
ubuntu environment deployment project