search
HomeOperation and MaintenanceLinux Operation and MaintenanceLinux installation of docker and summary of basic operations of docker

This article brings you how to install docker on Linux and the basic operations of docker. I hope it will be helpful to you.

Linux installation of docker and summary of basic operations of docker

1. Install docker

Docker is required to run on Centos 7, the system is required to be 64-bit, and the system kernel version is 3.10 or above

1.uname -an View the current system version

2.yum -y install docker Download and install docker

3.service docker start Start the docker service

4.docker version Check whether docker is installed successfully

When you see the information in the picture below, it means The local docker has been installed successfully, it is very simple

                                                 

2. Mirror operation

Creating a container must be based on the image, so first Let’s talk about the operation of docker images

Search for images

docker images ll Check whether the local machine already has an image

Currently there is no image in the machine, go to Docker Hub to download (the image can also be customized, I won’t go into details here)

docker search java , you can also specify a specific version to download,

For example: docker search Ubuntu: 1.2.5.4, you can search docker Hub and many images will be listed

Download the image

docker pull docker.io/nginx to download

The image downloaded locally is larger than the one searched on docker Hub because it is automatically decompressed during the download process , when viewing the image list, you will see the image you just downloaded

The list includes the warehouse name, version label, image ID, creation time and occupied space

##Delete image

Delete useless image docker rmi image id

3. Image creation and management

We have downloaded the Nginx image earlier, and then we will create a container with only Nginx application docker run -i -t /bin/bash: -i: standard input to the container -t: allocation A virtual terminal/bin/bash: execute the bash script,

docker run -idt --name container_nginx -p 8080:80  docker.io/nginx

Start a container using the image docker.io/nginx, named container_nginx, -p 8080:80 means mapping the container's port 80 to the host's 8080 port, so that we only need to access the 8080 port of the host to access the container's service.

Note: There are two - in front of the name, -p in front of the port, docker.io/nginx is the image name, 8080 is the port of the host, and 80 is the port of the Nginx application

A port on the host can only be mapped to one container port, and multiple container ports cannot correspond to one host port (if the container is installed on a centos-like system, the container port can be set casually, but if the container is It is just a simple application, then the container port should be the port of the application itself)

In this way we create and start a container!

exit 退出容器

docker ps 查看运行中的容器

docker ps -a  查看运行中和非运行中的所有容器

docker exec -it container_nginx /bin/bash  进入容器

如果容器还未启动 执行docker start container_nginx

Start Nginx after entering the container

whereis nginx 找Nginx的启动目录

[root@iz2zehzeir87zi8q99krk1z ~]# docker start container_nginx
container_nginx
[root@iz2zehzeir87zi8q99krk1z ~]# docker exec -it container_nginx /bin/bash
root@84683e425116:/# whereis  nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@84683e425116:/#  /usr/sbin/nginx

At this time, visit http://51.110.218.9:8080/ in the browser to directly access Nginx in the container

If the access is unsuccessful, it may be that the firewall of the host port is open. Execute the following command to close it

/ sbin / iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

Since I use the Alibaba Cloud server, I need to set port 8080 in Alibaba Cloud. Open

                             

Delete container

容器删除之前先将容器停止  

docker stop container_nginx 或者是容器的id

docker rm -f container_nginx  容器删除

The difference between docker start and docker run

docker start name 启动一个已经创建的容器

docker run 创建并启动一个容器
## The #docker run command is actually a combination of docker create and docker start. First execute docker create to create a container, and then docker start to start.

The host and container files copy each other

从主机复制到容器 sudo docker cp host_path containerID:container_path

从容器复制到主机 sudo docker cp containerID:container_path host_path

Please note that the above two commands are executed in the host and cannot be executed in the container

docker cp container_nginx:/usr/local/xin.txt  /usr/local/software/   容器向主机复制文件
docker cp /usr/local/xinzhifu.txt  container_nginx:/usr/local/  主机向容器复制文件

这样一个基础的docker容器就创建完了 。。。。。。。。。。。。

反过来大家再看一看docker的容器与镜像的区别  https://www.cnblogs.com/linjiaxin/p/7381421.html

那么其实镜像与容器的本质区别并不大,那么镜像可以生成容器 ,容器是否可以做成镜像呢?

docket commit container_nginx  image_nginx:v1
             
              容器名            自己起一个镜像的名字:版本号

 用当前的容器生成了redis镜像

例如:A、B两台机器都想安装redis,A机器上创建容器并在容器中做好redis的一切配置,让后将这个容器docker commit 成镜像image_redis,B机器也想要安装redis,直接用镜像image_redis创建容器就行了,docker就是做这样一劳永逸的事情。

而且传统方式得在每台机器上安装配置redis非常麻烦

四.镜像的导入与导出

镜像压缩打包 (主机上进行操作),有两种方式 docker save 与 docker load 和 docker export 与 docker import

docker save nginx | gzip > nginx_xin_image.tar.gz  将现有的镜像压缩打包

docker load -i nginx_xin_image.tar.gz  压缩的镜像解压

docker images 进行查看

docker save 是直接将镜像进行打包   docker save 或 

docker export container_nginx> nginx_image.tar  

cat nginx_image.tar | sudo docker import  - nginx_image:import

docker export 是直接将容器进行打包   docker save 或 

需要注意两种方法配套的,切不可混用。虽然导入导出时没问题,但是在创建容器时候会报错

如果使用import导入save产生的文件,虽然导入不提示错误,但是启动容器时会提示失败,

会出现类似"docker: Error response from daemon: Container command not found or does not exist"的错误。

类似,使用load载入export产生的文件,也会出现问题。

相关推荐:《Linux视频教程

The above is the detailed content of Linux installation of docker and summary of basic operations of docker. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
Linux: A Look at Its Fundamental StructureLinux: A Look at Its Fundamental StructureApr 16, 2025 am 12:01 AM

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

Linux Operations: System Administration and MaintenanceLinux Operations: System Administration and MaintenanceApr 15, 2025 am 12:10 AM

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Understanding Linux's Maintenance Mode: The EssentialsUnderstanding Linux's Maintenance Mode: The EssentialsApr 14, 2025 am 12:04 AM

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

How Debian improves Hadoop data processing speedHow Debian improves Hadoop data processing speedApr 13, 2025 am 11:54 AM

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

How to learn Debian syslogHow to learn Debian syslogApr 13, 2025 am 11:51 AM

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

How to choose Hadoop version in DebianHow to choose Hadoop version in DebianApr 13, 2025 am 11:48 AM

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

TigerVNC share file method on DebianTigerVNC share file method on DebianApr 13, 2025 am 11:45 AM

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno

Debian mail server firewall configuration tipsDebian mail server firewall configuration tipsApr 13, 2025 am 11:42 AM

Configuring a Debian mail server's firewall is an important step in ensuring server security. The following are several commonly used firewall configuration methods, including the use of iptables and firewalld. Use iptables to configure firewall to install iptables (if not already installed): sudoapt-getupdatesudoapt-getinstalliptablesView current iptables rules: sudoiptables-L configuration

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor