Docker installation and common commands

Docker installation and common commands

1, docker installation

1.yum update

yum update

2. Install required packages

Yum util provides the yum config manager function, and the other two are dependent on the devicemapper driver

yum install -y yum-utils device-mapper-persistent-data lvm2

3. Set yum source

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

4. Install docker

Press y when the input interface appears

yum install docker-ce  perhaps
yum install -y docker-ce

5. View docker version

docker -v

2, docker start

1. Start docker

systemctl start docker

2. Stop docker

systemctl stop docker

3. Restart docker

systemctl restart docker

4.docker status

systemctl status docker

5. Startup

systemctl enable docker

6.docker profile

docker info

7.docker help document

docker --help

3, Mirror correlation

1. View the image

docker images
docker images –q # View the id of the image used

2. Search image

Find the desired image from the network

docker search Image name

3. Pull the image

Download the image from the Docker warehouse to the local. The image name format is name: version number. If the version number is not specified, it is the latest version. If you don't know the image version, you can go to the docker hub to search for the corresponding image.

docker pull Image name:Version number

4. Delete image

docker rmi image id # Delete the specified local mirror
docker rmi `docker images -q`  # Delete all local mirrors

4, Container related

1. View container

docker ps # View running containers
docker ps –a # View all containers

2. Create and start the container

Parameter Description:

  • -i: Keep the container running. Usually used with - t. After adding the two parameters of it, the container will automatically enter the container after it is created. After exiting the container, the container will automatically close.

  • -t: Reassign a pseudo input terminal to the container, usually in conjunction with - i.

  • -d: Run the container in daemon (background) mode. To create a container to run in the background, you need to use docker exec to enter the container. After exiting, the container will not close.

  • -Containers created by it are generally called interactive containers, and containers created by - id are generally called guard containers

  • – Name: name the created container.

docker run parameter  
	Eg:docker run -id \
        -p 3307:3306 \
        --name=c_mysql \
        -v $PWD/conf:/etc/mysql/conf.d \
        -v $PWD/logs:/logs \
        -v $PWD/data:/var/lib/mysql \
        -e MYSQL_ROOT_PASSWORD=123456 \
        mysql:5.6 

Parameter Description:

  • -p 3307:3306: map the 3306 port of the container to the 3307 port of the host.

  • -v $PWD/conf:/etc/mysql/conf.d: set conf / my CNF is mounted to / etc / MySQL / my cnf. configure directory

  • -v $PWD/logs:/logs: mount the logs directory under the current directory of the host to / logs of the container. Log directory

  • -v $PWD/data:/var/lib/mysql: mount the data directory under the current directory of the host to / var/lib/mysql of the container. Data directory

  • **-e MYSQL_ROOT_PASSWORD=123456: * * initialize the password of root user.

3. Enter the container

docker exec parameter # Exit the container, and the container will not close Eg:docker exec – it c_mysql /bin/bash

4. Stop the container

docker stop Container name

5. Start the container

docker start Container name

6. Delete container

If the container is running, the deletion fails. You need to stop the container to delete it

docker rm Container name

7. View container information

docker inspect Container name

5, Container data volume

1. Configure data volumes

docker run ... –v Host Directory(file):In container directory(file) ... 
Eg:docker run -id --name=c_mysql -v $PWD/conf:/etc/mysql/conf.d \
	centos:7 /bin/bash 

6, Image making

1. Convert container to image

docker commit container id Image name:Version number                 Create a new image from the container
docker save -o Compressed file name image name:Version number           Save the specified image as tar Archive file
docker load –i Compressed file name                        Import use docker save Command exported image

Tags: Linux CentOS Docker Container

Posted by NFWriter on Sun, 22 May 2022 00:50:52 +0300