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

Learn from me Docker: start the first docker container (2)

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

As mentioned earlier, docker container is a kind of software packaging technology, so let's experience the difference between Docker and traditional mirror configuration.

Traditional compilation installs nginx:

Download the Nginx source package wget on the official website

Tar decompresses the source package

Create a Nginx user

Install the dependency package compile and install the trilogy configure,make,make install

Modify nginx configuration file

Start nginx

In the docker container:

Docker run-d-p 80:80 nginx

Run: create and run a container

-d: indicates running in the background

-p: Port Mappin

Name of the nginx:docker image

So here's how to install nginx in docker. Because of the wall, docker run-d-p 80:80 nginx does not take effect, as follows (connection timeout)

[root@docker01 /] # time docker run-d-p 80:80 nginx

Unable to find image 'nginx:latest' locally

Docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/nginx/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fnginx%3Apull&service=registry.docker.io: net/http: request canceled (Client.Timeout exceeded while awaiting headers).

See 'docker run-- help'.

Real 0m16.321s

User 0m0.021s

Sys 0m0.040s

[root@docker01 /] #

So before that, we need to do mirror acceleration.

1. Configure docker image acceleration (add the file manually and add the following code)

[root@docker01 /] # vi / etc/docker/daemon.json

{

"registry-mirrors": ["https://registry.docker-cn.com"]"

}

two。 Restart docker

[root@docker01 /] # systemctl restart docker

[root@docker01 /] #

3. Repeat the above steps: time docker run-d-p 80:80 nginx (timer means timing), as follows: docker startup error:

[root@docker01 /] # time docker run-d-p 80:80 nginx

Unable to find image 'nginx:latest' locally

Latest: Pulling from library/nginx

0a4690c5d889: Pull complete

9719afee3eb7: Pull complete

44446b456159: Pull complete

Digest: sha256:b4b9b3eee194703fc2fa8afa5b7510c77ae70cfba567af1376a573a967c03dbb

Status: Downloaded newer image for nginx:latest

C57ccf765ec7f8587d208fefbf6d35d7098e705105549de8fb6cb63bd264560e

Docker: Error response from daemon: driver failed programming external connectivity on endpoint trusting_lumiere (1d708b2c2a1294f393c272941975f95839714198e3553d20a8356c9b7916e32d): Error starting userland proxy: listen tcp 0.0.0.0 Error starting userland proxy 80: bind: address already in use.

Real 0m30.810s

User 0m0.042s

Sys 0m0.082s

[root@docker01 /] #

4.netstat-lntup checks the port listening situation and finds that port 80 has been monitored by http. In this case, you need to shut down the apache service.

[root@docker01 /] # netstat-lntup

5. Turn off the apache service. Most platforms now support IPv6, so apr also supports IPv6. By default, IPv6 is supported on all platforms except FreeBSD, NetBSD, and OpenBSD, so CentOS 7 also supports IPv6.

/ usr/sbin/apachectl stop

6. Rerun the docker service

[root@docker01 /] # time docker run-d-p 80:80 nginx

Efe791c12bb9c3c47915e07942278ae1e6b6cc78aa5ca5b9c4ad5327c3f83792

Real 0m0.618s

User 0m0.025s

Sys 0m0.025s

[root@docker01 /] #

7. Check the port again. Docker has successfully listened to 80.

[root@docker01 /] # netstat-lntup

8. The browser accesses nginx successfully.

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