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

How to configure docker for lightweight CVM Ubuntu18.4

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to configure docker on lightweight CVM Ubuntu18.4. Many people may not know much about it. In order to make you understand better, the editor summarizes the following contents. I hope you can get something from this article.

1. Demo system requirements

a. Cloud lightweight server ubuntu18.4

B. Ssh connection tool xshell6

Step # 1. Use xshell to connect to the server and update the apt installation source sudo apt-get update# 2. 0. Install the necessary system tools sudo apt-get-y install apt-transport-https ca-certificates curl software-properties-common# 3. Install the GPG certificate curl-fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg of docker-ce | sudo apt-key add-# 4. Write software source information sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release-cs) stable" # 5. Install and follow the new docker-ce (this is the official free version) sudo apt-get-y updatesudo apt-get-y install docker-ce3, verify installation docker version4, case understanding

Through the learning resources, my understanding of docker (beginners, personal understanding, if mistakes, please correct, common progress)

The Image image of each docker is like a mini linux virtual machine with the corresponding environment installed. Docker can manage these mirrors. For example, when pull comes down the images of a Nginx, you should have a "virtual machine" of the nginx environment, and you can also enter the interior through image id, just like the directory of linux. Very clean and lightweight, including only nginx configuration. Manage a container application with docker. The general value of an images image corresponds to a container, which only runs one application. Single principle, 3C principle. Projects that do not need to be packaged are deployed to container, and the images image should be closed. Package your packaged project, such as the vue project, as dist and upload it to any address on the server. Through docker, hang the directory on the image where Images is nginx, and then Container. In Images, the container application is port 80, and the directory should be configured under / usr/share/nginx/html/ of Images ("like virtual machine"). Open port 80, through the docker command, do directory and port mapping. Map it to the absolute address of the external dist, which is open to port 81. In this way, the application in docker can be accessed through the server ip address.

4.1. case explanation: online deployment of nginx by Docker

Pull images image (nginx)

Docker images# check the existing images # after installing docker, check the images. There are no images yet.

# docker search nginx check whether nginxdocker pull nginx# pulls a nginx image from dockerhub in dockerhub # docker images

At this point, the images image configured with nginx has been pulled down. (for example, a mini virtual machine with environment has finished nginx. Now we need to run our application inside and run the application through container).

Do you remember that the default directory is in / usr/share/nginx/html/ when nginx is not configured with docker? The default access port is ip: port 80. There will be a hello nginx page. What if we have to test it now? Docker needs to run the container container. Then change the container mapping dist and port

Upload locally packaged items to the specified directory.

I use new construction as a case here.

Cd / root# jumps to the root directory mkdir nginxcd nginx# to create a nginx folder mkdir vueDistData# to create vueDistData to store packaged projects cd vueDistDatavim index.html# to create random pages. It is accessed through container mapping. Cat index.html#, check what's in the index.html.

OK, which is now accessed through Images Nginx. First change the container configuration of Images Nginx and run

Docker run-- name nginx-v / root/nginx/vueDistData:/usr/share/nginx/html-p 80:80-d nginx#-- name maps the container to nginx#-v to map the local directory to the mirror container directory. There can be multiple mappings, and you can also map the nginx.config#-p port mapping, which maps the locally open ports to the mirrored container usage ports. At this time, the nginx image is executed in the background of 8 years-d ngixn.

# using docker ps to view the executing image and its container docker ps, you can see container id: container idimages: image created: creation time status: status ports: mapping out port and method tcpnames: name of container

Test access now

View server ip

Mine is 39.108.142.129. Visit 39.108.142.129 index.html 80 through the browser and see if you can access the index.html we wrote under / browser.

Although there are Chinese garbled codes, it is a success. So far, the nginx has been successfully deployed. Package the vue project into dist and put all the files in the dist into the vueDistData.

Have you found that it is still a little troublesome? it feels like a traditional nginx deployment.

As a matter of fact, docker should learn slowly. I deployed an Images for Nginx successfully, but next time it can not be apache tomcat and so on. I don't need to configure the environment and ports. Just drop it under the folder where the ports are mapped.

In fact, the real deployment does not need to be so troublesome. As described in the learning materials, configure everything through dockfile. This includes pulling images, naming containers, and mapping directory ports. It is then executed through docker build. Write dockerfile in the project, package it and store it in a random directory on the server, modify the dockfile, and then docker build will pull and configure everything according to the dockfile and deploy it automatically. I haven't learned it yet. So I won't introduce you.

4.2 docker Learning priority principles

3C single principle, one Images corresponds to one Container

Information such as data is generally not suitable for docker deployment. For example, the database, do not pull an Images down, in the images inside to do the database, docker mirroring of the variability is very strong, easy to cause data loss.

After reading the above, do you have any further understanding of how to configure docker for lightweight CVM Ubuntu18.4? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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

Internet Technology

Wechat

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

12
Report