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

What are the basic operations of Docker

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the relevant knowledge of "what are the basic operations of Docker". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

First, why use Docker?

Docker is an open source engine that automatically deploys development applications to containers. It was written by the Docker team and licensed under the Apache 2.0 open source agreement. It provides a simple, lightweight modeling method, makes the development life cycle more efficient and faster, and encourages service-oriented architecture design. The goal of the Docker project is to implement a lightweight operating system virtualization solution. Docker is based on technologies such as Linux container (LXC). Docker is further encapsulated on the basis of LXC, so that users do not need to care about the management of the container, making the operation easier. Users can manipulate Docker containers as easily as a fast and lightweight virtual machine.

Characteristics of Docker:

1, faster delivery and deployment

2, more efficient virtualization

3, easier migration and expansion

4, simpler management

Performance comparison between container technology and traditional virtual machines:

Comparison between Docker and Virtual Machine Construction

The Docker container is essentially a process on the host. Docker realizes resource isolation through namespace, resource restriction through cgroups, and efficient file operation through write-time copy mechanism (copy-on-write).

Docker has five namespaces:

Process, network, mount, host, and shared memory

In order to isolate problematic applications, Docker uses Namespace to isolate processes, create isolated running spaces for processes or process groups, and provide different namespace views for processes. Thus, each isolated process group is externally represented as a container (container). It is important to note that Docker makes users think that they occupy all the resources, but this is not a "virtual machine".

Three concepts in Docker: image, container, warehouse

1. Image: Docker image is a read-only template, which can be used to create Docker containers. Docker provides a simple mechanism to create or update an existing image, and users can even download an image from someone else to use it directly.

Mirroring is a file structure. Each command in Dockerfile creates a new hierarchy in the file system on which the file system is built, and the image is built on top of these federated file systems. The official Docker website has a dedicated page to store all available images at index.docker.io.

2. Container: a container is a running instance created from an image. It can be started, started, stopped, and deleted. Each container is an isolated and secure platform. Think of the container as a simple version of the Linux environment, and Docker uses the container to run applications. The image is read-only, and the container creates a writable layer as the top layer at startup.

3. Warehouse: a warehouse is a place where images are stored centrally. Multiple repositories are often stored on the warehouse registration server (Registry), and each warehouse contains multiple images, each with a different tag. Currently, the public repository of * is Docker Hub, which stores a large number of images for users to download.

The Docker repository is used to store our images, and after we have created our own image, we can use the push command to upload it to a public or private warehouse, so that the next time we want to use this image on another machine, we just need to pull it from the warehouse. The concept of a Docker repository is similar to that of Git, and the registration server can be understood as a managed service such as GitHub.

Second, install Docker

Prerequisite: Docker is highly demanding to run on the kernel, so it is generally recommended to run directly on a platform like Ubuntu. But as a container standard, Docker also supports other platforms such as CentOS, Mac OS X, Windows and so on. Docker currently supports the following versions of CentOS:CentOS 7 (64-bit) CentOS 6.5 (64-bit) and later versions of CentOS 6.5 and later, kernel versions > = 2.6.32-431 are required because these kernels contain specific modifications to run Docker.

Docker uses AUFS as the storage driver by default, but AUFS is not included in the mainline kernel of Linux. Device Mapper can be used as a storage driver in CentOS, a new feature introduced in the 2.6.9 kernel version. We need to confirm that this feature is enabled first:

CentOS 7 installation

The Docker RPM package is already included in the CentOS-Extra repository, so we can install it directly using Yum:

# yum install docker

CentOS 6.6 installation

It is important to note that there is already an executable system package with the same name docker in CentOS6.6. So the Docker RPM package is named docker-io, and we uninstall docker first.

# yum-y remove docker

Step 3 Install Docker-IO

# yum-y install docker-io

This completes the installation of Docker.

# / etc/init.d/docker start # launch docker # docker info # to view basic docker information

Third, basic operation of Docker

# docker search centos # search container # docker pull centos # download container # docker images # View the current image # docker run centos / bin/echo 'hello world' # run a command and then directly exit # docker run-name mydocker-it centos / bin/bash # enter the docker container-t option to let Docker assign a pseudo terminal (pseudo-tty) and bind to the container's standard input -I keeps the standard input of the container open. -name starts the nginx image with a custom name # docker run-d-- name mynginx nginx # without automatically pull # docker stop bfd094233f96 # stops a container, deletes according to container id # docker rm bfd094233f96 # deletes a container # docker attach d20f3dc6cd92 # enters a running container this command is not very useful It is recommended to use the following command to enter the container: [root@localhost docker] # docker inspect-- format "{{State.Pid}}" mynginx # get container pid 19769 [root@localhost docker] # nsenter-- target 19769-- mount-- uts-- net-- pid # enter the container (recommended method) # docker run-d-p 91:80-- name mynginx2 nginx #-p specifies the port mapping, mapping 80 to 91 of host

Storage Mirror:

# docker save-o ubuntu_14.04.tar ubuntu:14.04

Load the image:

# docker load < ubuntu_14.04.tar or use # cat ubuntu.tar | docker import-test/ubuntu:v1.0

Remove the local mirror:

# docker rmi training/sinatra

Clean up all untagged local images:

# docker rmi $(docker images-Q-f "dangling=true") where-Q and-f are abbreviations for quiet,-filter, and the complete command can actually be written as follows, isn't it easier to understand? # docker rmi $(docker images-- quiet-- filter "dangling=true") Note: whether the container will run for a long time depends on the command specified by docker run and has nothing to do with the-d parameter.

To get the output of the container, you can use the docker logs command.

# docker logs [container ID or NAMES]

Delete the container:

# docker rm does not delete running containers by default

Underlying information about containers and images:

# docker inspect container/image

You can view:

IP address port binding list of container instance

Search for specific port mappings

Collect configuration details

Copy the file from within the container to the specified path:

Docker cp container:path hostpath

Use Dockerfile to build the image:

Docker build [options] PATH | URL-rm=true means that after the construction is successful, remove all intermediate containers-no-cache=false means that the cache "what are the basic operations of Docker" is not used during the construction process. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Internet Technology

Wechat

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

12
Report