One, foreword

Before Docker deploys an application project, there are a few things to do first. For example, CentOS 7 operating system and network environment. This article is based on CentOS 7 operating system Docker installation, listing the common Docker commands.

Second, the concept of

First, Docker is an open source application container engine that allows developers to package their applications and dependencies into a lightweight, portable container. And then distribute it to any Linux machine, virtualization, operating system level virtualization technology.

Docker advantages:

  • More efficient use of system resources

  • Faster startup time

  • Consistent operating environment

  • Continuous delivery and deployment

3. Installation steps – Docker is installed within the software source

  1. Yum source update to install required dependencies
 yum update
 yum install -y yum-utils device-mapper-persistent-data lvm2
Copy the code
  1. Configure Docker warehouse, recommended to use Ali source
# official yum source, slow speed
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo  
# ali source
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 
Copy the code
  1. Install the docker
yum -y install docker-ce
docker -v
Copy the code
  1. Configure the Docker image source
vim /etc/docker/daemon.json
{
  "registry-mirrors" : [
    "https://o9xov9fj.mirror.aliyuncs.com"."https://dockerhub.azk8s.cn"."https://registry.docker-cn.com"."https://7ky1d6ld.mirror.aliyuncs.com"]}Copy the code
  1. Start the Docker
systemctl start docker
Copy the code

Docker common commands

  1. Common Docker image commands
# mirror
docker images 
# search mirror
docker search centos 
# pull mirror
docker pull centos 
docker pull centos:7  
Delete an IMAGEID as the IMAGEID
docker rmi  IMAGEID   
# Delete all mirrors
docker rmi 'docker images -q' 
Copy the code
  1. Common Docker container commands
# View the running container
docker ps    
# View all containers
docker ps -a  
# create a containerDocker run -i run after container - t container startup will enter the command line - the name vessel named -v hosting and container directory mapping - d create a tutelary container is running in the background (thus create container will not automatically log in container, if only add - I - t two parameters, -p indicates port mappingCentos :7 indicates the image name
# (The container will not run after exit)
docker run -it --name=mycentos  centos:7 /bin/bash 
# (daemon created)
docker run -di --name=mycentos2 centos:7
# directory mapping
docker run -di -v /root/data/:/root/data/ --name mycentos3 centos:7 
Enter the docker command line
docker exec -it mycentos2  /bin/bash  
CONTAINERID specifies the ID of the docker containerDocker stop CONTAINERID Starts the Docker container docker start CONTAINERIDCopy host files to docker containerDocker cp Host file directory CONTAINERID: CONTAINERID file directoryCopy the docker files to the host directoryDocker cp CONTAINERID: CONTAINERID directoryCheck the container information
docker inspect CONTAINERID --format="{{.NetworkSettings.IPAddress}}"   
# delete container
docker rm CONTAINERID 
Copy the code

5. Container Running (Example)

  1. Run and start the container
docker run -it --name mycentos -p 80:80 centos:7
Copy the code
  1. Go to the container directory and perform operations
docker exec -it  CONTAINERID /bin/bash 
Copy the code

Sixth, the end

This article is mainly Docker installation and basic commands. The deployment of Docker, including the Node container and the Nginx container (based on the blogging system being built), will be covered in detail in the next article.

Public account: Front-end technology research circle