Container Technology Fundamentals (3)

Introduction: Quickly learn the basics of container technology. The course will start with the basics of container technology. It will explain how container technology is implemented based on technologies such as Namespace and Cgroups in the linux kernel, and the development background and basic knowledge of Docker containers. The relationship between , CRI and Kubernetes has generated new awareness.
The developer school course [ Modern Application Container Technology Quick Start Third Lesson: Container Technology Fundamentals (3)] study notes, which are closely related to the course, allowing users to quickly learn knowledge.

Container Technology Fundamentals (3)

brief introduction
1. Install docker
2. Configure Alibaba Cloud Image Acceleration
3. Common docker commands

1. Install docker
docker CE : docker community edition
docker EE : docker enterprise version
1. Clear the old version
sudo apt-get remove docker docker-engine containerd runc
2. Installation
sudo apt-get update sudo apt-get install

3. Test docker
sudo docker run hello-world

2. Configure Alibaba Cloud Image Acceleration
1. Go to Alibaba Cloud's Docker container image service to apply
Container image service address
2. After logging in, first create a new namespace

3. Create a new mirror warehouse

Choose a local warehouse

4. Configure Image Accelerator

5. Test
docker run hell-world

3. Common docker commands

| View native images
docker images [option] #List all the images on this machine #The header of the displayed result means the following
#RESPITORY Mirror repository source
#TAG The label of the image [The unified repository source can have multiple TAGs to specify different versions]
# IMAGE ID image
#CREARED Image creation time
#SIZE Image size
# option :
# -a lists all local images (including intermediate image layers)
# -q only displays image ID
# --digests displays summary information of images
# -- no-trunc shows full mirror information
| Search for mirrors in the warehouse
docker search [options] #Search for mirrors in the remote repository#option
# --no-trunc displays the complete mirror description
# -s lists the mirrors whose collection is not less than number
# --automated only lists the mirrors of the automated build type
| Get Mirror
docker pull [:TAG] #Get the specified image from the remote library, if you add the version, you will get the specified version, if you don't add it, you will get the latest version
| Delete mirror
docker rmi -f error! No filename specified. #Delete the mirror with the specified mirror ID docker rmi -f #Delete multiple
| commit image
docker commit -m="commitInfo" -a="author" :[tag name]
container directive
| Create a new container and run
docker run [options] error! No filename specified. [command] [arg...] #Create and start a container# options description
# --name= name: specify a name for the container
# -d run in the background and return the container ID, that is, start the daemon container
# -i to Running the container in interactive mode
# -t reassigns a pseudo input terminal to the container, usually used with -i
# -P random port mapping
# -p specifies port mapping
# Demonstration:
docker run -it -p 80:8080 tomcat #Create Tomcat The container is started, and the port 80 of the host is mapped to port 8080 of the container

| View Containers
docker ps [options]# options
# -a lists all currently running + historically running containers
# -l lists recently created containers
# -n shows the number of recently created containers
# -q only shows containers Numbering
| Exit container
exit #The container stops and exits ctrl+P+Q #The container does not stop and exit
| restart & start & stop container
docker start #Start the container docker restart
#Restart the container docker stop #Stop the container
docker kill #Forcibly close the container
| View container logs
docker logs [options] # options
# -t add timestamp
# -f follow the latest log print
# --tail display
| View the processes in the container
docker top #Display the process inside the current container
| Enter the [running] container and interact with the command line
docker exec - it docker attach
| Copy files from the container to the host
docker cp :
| Container Data Volume
A volume is a directory or file that exists in one or more containers and is mounted to the container by docker. The design purpose of the volume is the persistence of data, which is completely independent of the life cycle of the container, so docker will not delete the mounted data volume when the container is deleted.
1. Data volumes can share or reuse data in container primary keys
2. Changes in the volume can take effect directly
3. Changes in the data will not be included in the update of the mirror
4. The lifecycle of a data volume lasts until no containers use it
| Add directory mapping between container and host
docker run -it -v : #read-write docker run -it -v ::ro #read-only

Copyright statement: The content of this article is contributed by Alibaba Cloud's real-name registered users. The copyright belongs to the original author. The Alibaba Cloud developer community does not own the copyright and does not assume the corresponding legal responsibility. For specific rules, please refer to the " Alibaba Cloud Developer Community User Service Agreement " and " Alibaba Cloud Developer Community Intellectual Property Protection Guidelines ". If you find any content suspected of plagiarism in this community, fill out the infringement complaint form to report it. Once verified, this community will delete the allegedly infringing content immediately.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us