Docker basic commands

Build image: docker build-t < image >
View images: Docker images/Docker image ls
Docker rmi < ID>
Create container: docker run -itd -p < map port > –link < container connection > < mirror > bash

docker run -itd -p 8080:8080 --link 9fjkn4544vf:localhost test-app bash

Docker ps-A docker Ps-A
Docker stop < container ID>
Docker start < container ID>
Docker restart < container ID>
Docker rm < container ID>
Docker pull < image >
Docker tag < tag> < tag: tag>

Docker tag ubuntu: username/ubuntu 18.04:18.04

Docker login docker login
The warehouse logged out of the Docker logout
Docker push < image >

Second, the Dockerfile

A Dockerfile is a text file used to build an image. The text content contains the instructions and instructions required to build the image

Here is a post from the rookie tutorialDockerfileI won’t write it, but I’ll post the Dockerfile I use
FROM java:8
EXPOSE 8080

#Defining time Zone Parameters
ENV TZ=Asia/Shanghai
#Set the time zoneRUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone VOLUME /tmp ADD ./zs_api_jar/* app/ RUN  bash -c 'touch app/' ENTRYPOINT ["java","-jar","app/zs-api.jar"]Copy the code

Iii. Docker private warehouse construction

Docker officially provides a public repository -hub.docker.com, where you can register an account and use Docker login to login. The locally constructed image is pushed into the public repository, like general open source projects, where you can find the image and directly pull it down to use. Don’t install like the traditional way before, such as nginx, Redis and other common software.


However, in the actual development of the company, it is impossible to push the project image into the public warehouse, so the enterprise generally builds its own private Docker warehouse to meet the needs of use.
Docker official Docker repository project open source, you can use it to build. There is also an open source project that is more useful — Harbor. In addition to integrating docker warehouse, harbor also provides image management system, which can set different permissions for users to better manage online versions.

Set up

1. Preconditions
  • Install docker and run it
Yum install docker # yum install docker... Systemctl start dockerCopy the code
  • Install the docker – composeyum install docker-compose
2. Download the installation package

If you can access Github quickly enough, Recommended wget directly at https://github.com/goharbor/harbor/releases/download/v1.9.4/harbor-offline-installer-v1.9.4.tgz

If the access speed is not good, you can find domestic sources to downloadharbor.orientsoft.cn/But the version is not up to date

Decompress the installation package tar -zxvf harbor-offline-installer-v1.7.1. TGZ

3. Edit the configuration file

In the project directory, there is a file called harbor. CFG, which is the configuration file

The hostname needs to be changed to the server domain name or public IP address. If there is no HTTPS related configuration, you need to change itcustomize_crt=falseSupports HTTP access.
Note: for HTTP access, edit /etc/docker-daemon. json for docker
{
    "insecure-registries":["hub.docker.*.com:3333"]
}
Copy the code
Then restart Docker
4. Start the harbor

After modifying the configuration file, run./prepare to run./install.sh

After the startup, you can access host in the browser and see the Harbor management page, indicating that the startup is successful. At the same time, docker PS can also see that several containers about Harbor are running on the right.

Then you can use the docker login command to login to your account. If the login is successful, there is no problem.
5. Manage commands
Docker-compose up -p or docker-compose start
Docker-compose down -d or docker-compose stop

use

Login private repository: Docker Login
Docker pull < image >
Docker tag < tag> < tag :tag>
Docker push < image >

GUI can also be used to manage the background, users, warehouses, projects and so on.


It is worth noting that it is recommended to use a new server to build the Docker warehouse and try not to build it on the server with multiple projects running, because if harbor uses port 80 other than nginx for forwarding, it will lead to errors in the management page path. Moreover, the image occupies a large bandwidth when pushing, so it is recommended to have a server dedicated to private warehouse, and the image itself also occupies a large amount of server storage space.