Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The concept of Docker and the arrangement of Common commands

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "the concept of Docker and the arrangement of common commands". In the daily operation, I believe that many people have doubts about the concept of Docker and the arrangement of commonly used commands. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "the concept of Docker and common commands". Next, please follow the editor to study!

First, the picture above:

Basic concepts of Dcoker

Docker includes three basic concepts:

Image: a Docker image is a special file system that not only provides programs, libraries, resources, configuration files, etc., but also contains some configuration parameters (such as anonymous volumes, environment variables, users, etc.) prepared for the runtime. The mirror does not contain any dynamic data, and its content will not be changed after it is built.

Container: the relationship between Image and Container, just like classes and instances in object-oriented programming, the image is a static definition, and the container is the entity of the mirror runtime. Containers can be created, started, stopped, deleted, paused, and so on.

Repository: Repository is a remote warehouse similar to Git, which centrally stores image files.

The relationship between the three can be shown in the following figure:

Next, take a look at the common commands of Docker.

Service

View Docker version information

Docker version

View docker profile

Docker-v

Start Docker

Systemctl start docker

Close docker

Systemctl stop docker

Set up boot boot

Systemctl enable docker

Restart the docker service

Service docker restart

Turn off the docker service

Service docker stop Image Repository

A large number of high-quality images are available on Docker Hub and other image repositories, and you can obtain images from the repository.

Retrieve the image

Docker search keyword

Pull the image

Docker pull [option] [Docker Registry address [: Port number] /] Repository name [: label] Image Management

List Mirror

Docker image lsdocker images

Delete Mirror

# Delete the specified image docker rmi

Export Mirror

# Save the image as an archive file docker save

Import Mirror

Docker loadDockerfile builds an image

Dockerfile is a matching file in text format, and users can use Dockerfile to quickly create custom images.

Dockerfile consists of line-by-line command statements and supports comment lines that begin with #.

Dockerfile common instructions

Here are some common instructions in Dockerfile:

FROM: specify the base image

RUN: execute command

COPY: copying fil

ADD: more advanced copy files

CMD: container startup command

ENV: setting environment variabl

EXPOSE: exposed port

Other instructions include ENTRYPOINT, ARG, VOLUME, WORKDIR, USER, HEALTHCHECK, ONBUILD, LABEL, and so on.

The following is an example of Dockerfile:

FROM java:8MAINTAINER "jinshw" ADD mapcharts-0.0.1-SNAPSHOT.jar mapcharts.jarEXPOSE 8080CMD java-jar mapcharts.jar image construction docker build image run

To run a mirror is to create and run a container.

Docker run [Mirror ID] Container container lifecycle

Startup: there are two ways to start a container, one is to create a new container based on the image and start it, and the other is to restart the container in the stopped state.

# create and launch docker run [image name / image ID] # launch terminated container docker start [container ID]

View the container

# list containers running on this machine $docker ps # list all containers on this machine (including stopping and running) $docker ps-a

Stop the container

# Container docker stop [Container ID] # Kill Container process docker kill [Container ID]

Restart the container

Docker restart [Container ID]

Delete Container

Docker rm [Container ID] enters the container

There are two ways to enter the container:

# if you exit from this stdin, it will cause the container to stop docker attach [Container ID] # Interactively enter Container docker exec [Container ID]

The second method is usually used to enter the container. The common parameters followed by docker exec are as follows:

-d,-- detach executes commands in the background in the container

-I,-- interactive=true I false: open standard input to accept user input commands

Export and Import

Export Container

# Export a created container to a file docker export [Container ID]

Import Container

# exported container snapshot files can be re-imported as mirror docker import [path] other

View the log

# exported container snapshot files can be re-imported as mirror docker logs [Container ID]

This command has the following common parameters

-f: trace log output

-since: displays all logs at a certain start time

-t: displays the timestamp

-tail: only the latest N container logs are listed

Copy a file

# copy from the host to the container sudo docker cp host_path containerID:container_path # copy from the container to the host sudo docker cp containerID:container_path host_path

At this point, the study of "the concept of Docker and common commands" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report