This time I will explain the use of building local docker and docker
My computer Windows10 system, install the docker quick installation package, address: https://docs.docker.com/docker-for-windows/install/#download-docker-for-windows
After the download is complete, fool-like installation;
Installed and used
1: docker --version command to view version information
2: docker ps check whether the command is working properly
3: Log in to Aliyun docker: https://cr.console.aliyun.com/cn-beijing/instances/repositories
4: Create a mirror warehouse
5: View the basic information of the warehouse, log in, upload, and pull mirrors according to the prompts
6: Upload the local image to the Alibaba Cloud server
6.1: Package a local image, usually a project is placed in a folder, for example, there is a project on the official website called flask-app, then all the files are in the project directory, we need to add a "Dockerfile" under the project root directory Text file, and remove its txt suffix, and then use a normal text editor to write the Docker environment, such as the following Dockerfile (the introduction of dockerfile is searched by Baidu, so I won’t explain it in detail here):
FROM java:8
MAINTAINER six
VOLUME /data
COPY ./application/application.properties application.properties
ADD /target/mq-demo-0.0.1-SNAPSHOT.jar mq-demo-0.0.1-docker.jar
RUN export LC_ALL=zh_CN.UTF-8
RUN echo "export LC_ALL=zh_CN.UTF-8" >> /etc/profile
RUN echo "Asia/shanghai" > /etc/timezone
RUN bash -c 'touch mq-demo-0.0.1-docker.jar'
EXPOSE 8799
ENTRYPOINT ["java","-jar","-XX:MetaspaceSize=128m","-XX:MaxMetaspaceSize=256m","-Xms256m","-Xmx256m","-Xmn128m","-Xss256k","-XX:SurvivorRatio=8","-XX:+UseConcMarkSweepGC","mq-demo-0.0.1-docker.jar","--spring.config.location=application.properties"]
6.2: Create an application folder at the same level of dockerfile and store application.properties
6.3: The local need to package the folder directory cmd to enter the command line to log in to docker: docker login [email protected] registry.cn-shanghai.aliyuncs.com
6.4: Packaged image: docker build. (The last point cannot be ignored)
6.5: Modify the image tag name: docker tag 0a1da98e86eb registry.cn-shanghai.aliyuncs.com/java/mq:3.7 (0a1da98e86eb: represents the image id)
6.6: Upload the image to Alibaba Cloud server: docker push registry.cn-shanghai.aliyuncs.com/java/mq:3.7
7: Pull Alibaba Cloud image
7.1: Login docker command: docker login [email protected] registry.cn-shanghai.aliyuncs.com
Pull image command: docker pull registry.cn-shanghai.aliyuncs.com/java/mq:3.7
8: Add docker-compose.yml to the linux server, as follows
version: '1'
services:
mq-demo:
container_name: mq
image: registry.cn-shanghai.aliyuncs.com/java/mq:3.7
ports:
- '7788:8080'
volumes:
- /data/log:/log:rw
- /etc/localtime:/etc/localtime:ro
9: Start the project: docker-compose up -d mq-demo
10: Stop the project: docker-compose stop mq-demo
11: View logs: docker logs -f --tail 20 mq-demo //20 represents the number of log lines
12: docker ps------View the running cotainners
13: docker ps -a -------- view all containners
1:4: docker restart container id