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 is the method of using docker in Linux installation

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "Linux installation using docker method is what", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "Linux installation using docker method is what" it!

one。 Install docker

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

1.uname-an to view the current system version

2.yum-y install docker download and install docker

3.service docker start starts the docker service

4.docker version checks whether docker is installed successfully

When you see the information in the following figure, it means that the native docker has been installed successfully. It is very simple.

two。 Mirror operation

Creating a container is based on image, so let's talk about the operation of docker image first.

Search for an image

Docker images ll to check whether the local server already has an image.

At present, there is no image in the machine. Go to Docker Hub to download it (the image can be customized, so I won't go into details here)

Docker search java, and you can specify a specific version to download.

For example: docker search Ubuntu:1.2.5.4, you can search docker Hub will list a lot of images

Download the image

Download with docker pull docker.io/nginx

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

Delete Mirror

Delete useless image docker rmi image id

three。 Creation and Management of Mirror

Now that we have downloaded the Nginx image, let's create a container with only Nginx applications: docker run-I-t / bin/bash:-i: standard input to the container-t: assign a virtual terminal / bin/bash: execute the bash script

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

Start a container using the mirror docker.io/nginx with the name container_nginx.-p 8080 means to map port 80 of the container to port 8080 of the host, so that we can access the service of the container by accessing port 8080 of the host.

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

A port on a host can only be mapped to one container port, and multiple container ports cannot correspond to one host port (if the container installs a centos system, then the container port can be set freely, but if the container is only for simple application, then the container port should apply its own port)

So we created and started a container!

Exit exit Container docker ps View running Container docker ps-a View all running and non-running containers docker exec-it container_nginx / bin/bash enter the container if the container has not already started to execute docker start container_nginx

Start Nginx after entering the container

Whereis nginx finds the Nginx startup directory [root@iz2zehzeir87zi8q99krk1z ~] # docker start container_nginxcontainer_ nginx [root @ iz2zehzeir87zi8q99krk1z ~] # docker exec-it container_nginx / bin/bashroot@84683e425116:/# whereis nginxnginx: / usr/sbin/nginx / usr/lib/nginx / etc/nginx / usr/share/nginxroot@84683e425116:/# / usr/sbin/nginx

At this point, you can directly access the Nginx in the container by accessing http://51.110.218.9:8080/ in the browser.

If the access is not successful, the firewall of the host port may be on. Execute the following command to turn it off.

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

Because I use the Ali cloud server, I need to open port 8080 in Aliyun.

Delete Container

Delete the docker stop container_nginx or iddocker rm-f container_nginx container of the container before deleting the container

The difference between docker start and docker run

Docker start name starts a created container docker run creates and starts a container

The docker run command is actually a combination of docker create and docker start commands. First execute docker create to create a container and then start with docker start.

Host and container files copy each other

Copy from host to container sudo docker cp host_path containerID:container_path copy from container to host sudo docker cp containerID:container_path host_path

Please note that both of the above commands are executed on the host and cannot be executed in the container

The docker cp container_nginx:/usr/local/xin.txt / usr/local/software/ container copies files to the host

The docker cp / usr/local/xinzhifu.txt container_nginx:/usr/local/ host copies files to the container

Such a basic docker container is created.

On the other hand, let's take a look at the difference between docker containers and images, https://www.cnblogs.com/linjiaxin/p/7381421.html.

In fact, there is not much difference between an image and a container, so an image can generate a container. Can a container be made into an image?

The docket commit container_nginx image_nginx:v1 container name has its own image name: version number.

A redis image is generated with the current container

For example, both An and B machines want to install the container on the redis,A machine and do all the configuration of redis in the container, and then make the container docker commit as if the image_redis,B machine also wants to install redis. Just use the image image_redis to create the container. Docker is to do this once and for all.

And the traditional way to install and configure redis on each machine is very troublesome.

four。 Import and export of images

Image compression packaging (operation is performed on the host). There are two ways: docker save and docker load and docker export and docker import

Docker save nginx | gzip > nginx_xin_image.tar.gz packages the existing image compression docker load-I nginx_xin_image.tar.gz compressed image decompression docker images to view

Docker save is to package the image directly, docker save or

Docker export container_nginx > nginx_image.tar cat nginx_image.tar | sudo docker import-nginx_image:import

Docker export is to package the container directly, docker save or

Need to pay attention to the matching of the two methods, must not be mixed. Although there is no problem with import and export, an error will be reported when creating the container

If you use import to import a file generated by save, although the import does not prompt an error, it will prompt a failure when starting the container

An error similar to "docker: Error response from daemon: Container command not found or does not exist" occurs.

Similarly, there are problems with loading files generated by export using load.

Thank you for your reading, the above is the content of "what is the method of installing Linux using docker". After the study of this article, I believe you have a deeper understanding of what the method of installing Linux using docker is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Servers

Wechat

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

12
Report